返回字典
返回的值是字符串,用JSON转换回字典
应用场景:
数据传输时:
- 发送:字符串
- 接收:字符串 -->对象
$.ajax({
url:'/add_student/', #路由指向
type: 'POST', #传输方式
data:postData, #传输内容
success:function (arg) { #传输成功后的回调函数,返回值为arg,为一个字符串
var dict=JSON.parse(arg); #转换为字典
if(dict.status) { #返回值中字段status的判断
window.location.reload(); #页面刷新
}else {
$('#errorMsg').text(dict.message); #把字典中的message内容,放到id为errorMsg的位置
}
}
})
再来一个
$.ajax({
url:'/del_student/',
type:'GET',
data:{'rowId': rowId},
dataType:'JSON', //
success(arg){
if(dict.status){
$('tr[nid="'+rowId+'"]').remove();
}
$('#delModal').modal('hide');
}
})
第二个与下面的等同
$.ajax({
url:'/del_student/',
type:'GET',
data:{'rowId': rowId},
dataType:'JSON', //
success(arg){
if(dict.status){
$('tr[nid="'+rowId+'"]').remove();
}
$('#delModal').modal('hide');
}
})