欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jquery中ajax請求后臺數(shù)據(jù)成功后既不執(zhí)行success也不執(zhí)行error的完美解決方法

 更新時間:2017年12月24日 12:01:51   作者:Sumyn  
這篇文章主要介紹了jquery中ajax請求后臺數(shù)據(jù)成功后既不執(zhí)行success也不執(zhí)行error解決方法,需要的朋友可以參考下

jquery中ajax請求后臺數(shù)據(jù)成功后既不執(zhí)行success也不執(zhí)行error,此外系統(tǒng)報錯:Uncaught SyntaxError: Unexpected identifier at Object.success,但后臺能夠返回數(shù)據(jù),原代碼如下:

 var source=[];
$.ajax({   
  type: "post",   
  url: "connectdb/select.jsp",    
  data: {database: "scmdb", selectsql: sql}, 
  async: false, method: 'post',  
  dataType: "json", 
  success: function(data) {   
    eval("source="+data+";");
    //source=eval(data); 
    alert("正確");
  },
  error: function(err) {  
    alert("錯誤");   
  }
});
return source;  

主要原因在于后臺返回的數(shù)據(jù)并非json格式,而在代碼中指定了 dataType: "json", 解決方法是將 json改為text,修改后的代碼如下:

 var source=[];
$.ajax({   
  type: "post",   
  url: "connectdb/select.jsp",    
  data: {database: "scmdb", selectsql: sql}, 
  async: false, method: 'post',  
  dataType: "text", 
  success: function(data) {   
    eval("source="+data+";");
    //source=eval(data); 
    alert("正確");
  },
  error: function(err) {  
    alert("錯誤");   
  }
});
return source; 

總結(jié)

以上所述是小編給大家介紹的jquery中ajax請求后臺數(shù)據(jù)成功后既不執(zhí)行success也不執(zhí)行error解決方法,希望對大家有所幫助!

相關(guān)文章

最新評論