jquery Ajax 不執行回調函數success的緣由

jquery Ajax 不執行回調函數success的緣由:jquery

$.ajax({
type: "post",
contentType: "application/json",
url: basePath+"pages/Tongji/disposeAgree.action?cepingitem="+cepingitem+"&userrelation="+userrelation,
//data: {fenshu:8},
dataType: "json",
success: function (result) {
alert("操做成功");


},
error:function(response){
alert("error");
}
});git

如上,由於設置了屬性dataType:"json",故若是後臺返回的不是正確的JSON字符串,那麼永遠不執行回調函數success,而只執行error函數。要麼返回正確的JSON字符串,要麼把dataType屬性改成textajax

正確的返回JSON字符串以下:json

pw.write("{\"name\":\"zs\"}");app

pw.write("{\"name\":"+true+"}");函數

錯誤的例子:post

pw.write("{name:zs}");url

相關文章
相關標籤/搜索