jquery Ajax 不執行回調函數success的原因


jquery Ajax 不執行回調函數success的原因:

$.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");
}
});

如上,因為設置了屬性dataType:"json",故如果后台返回的不是正確的JSON字符串,那么永遠不執行回調函數success,而只執行error函數。要么返回正確的JSON字符串,要么把dataType屬性改為text

正確的返回JSON字符串如下:

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

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

錯誤的例子:

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM