新聞中心
小編給大家分享一下jQuery Ajax Post 回調(diào)函數(shù)不執(zhí)行的解決方法,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
回調(diào)的JSON數(shù)據(jù)格式問題,導(dǎo)致回調(diào)函數(shù)一直無法執(zhí)行;jQuery Ajax Post 回調(diào)函數(shù)不執(zhí)行的解決辦法:JSON數(shù)據(jù)都要用雙引號,使用轉(zhuǎn)義字符轉(zhuǎn)義String,代碼為【{\"hello\":\"world\"}】。
jQuery Ajax Post 回調(diào)函數(shù)不執(zhí)行的解決辦法:
1、前臺代碼
$.post('${pageContext.request.contextPath}/user_deleteUser',{uid:row.uid},function(result){ if (result.errorMsg){ $.messager.show({ title: 'Error', msg: result.errorMsg }); } else { $('#dg').datagrid('reload'); } },'json');
2、后臺代碼
public String deleteUser() { int count = userDao.deleteUser(model.getUid()); try { PrintWriter writer = response.getWriter(); if(count<=0) writer.write("{'errorMsg':'刪除失敗'}"); else writer.write("{'success':'刪除成功'}"); } catch (IOException e) { e.printStackTrace(); } return null; }
很明顯前臺代碼并沒有什么問題,后臺代碼在邏輯上貌似也沒什么問題,最后百度得知回調(diào)的JSON數(shù)據(jù)格式問題,導(dǎo)致回調(diào)函數(shù)一直無法執(zhí)行,原來JSON數(shù)據(jù)都要用雙引號!
我的:{'hello':'world'} 標(biāo)準(zhǔn):{"hello":"world"}
由于String不能雙引號嵌套使用所以我們用轉(zhuǎn)義符即可
{\"hello\":\"world\"}
以上是“jQuery Ajax Post 回調(diào)函數(shù)不執(zhí)行的解決方法”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
文章標(biāo)題:jQueryAjaxPost回調(diào)函數(shù)不執(zhí)行的解決方法-創(chuàng)新互聯(lián)
分享URL:http://fisionsoft.com.cn/article/cshish.html