返回字典
返回的值是字符串氛驮,用JSON轉(zhuǎn)換回字典
應(yīng)用場景:
數(shù)據(jù)傳輸時:
- 發(fā)送:字符串
- 接收:字符串 -->對象
$.ajax({
url:'/add_student/', #路由指向
type: 'POST', #傳輸方式
data:postData, #傳輸內(nèi)容
success:function (arg) { #傳輸成功后的回調(diào)函數(shù)凯亮,返回值為arg伙窃,為一個字符串
var dict=JSON.parse(arg); #轉(zhuǎn)換為字典
if(dict.status) { #返回值中字段status的判斷
window.location.reload(); #頁面刷新
}else {
$('#errorMsg').text(dict.message); #把字典中的message內(nèi)容,放到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');
}
})