jquery中ajax請求后臺數據成功后既不執行success也不執行error,此外系統報錯:Uncaught SyntaxError: Unexpected identifier at Object.success,但后臺能夠返回數據,原代碼如下:
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;
主要原因在于后臺返回的數據并非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;
相信看了本文案例你已經掌握了方法,更多精彩請關注Gxl網其它相關文章!
推薦閱讀:
jQuery EasyUI 折疊面板的使用
jQuery EasyUI選項卡面板的tabs使用
jQuery向動態列表添加新元素
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com