Home > Article > Web Front-end > What should I do if the post callback function in jquery does not execute?
The solution to the problem that the post callback function in jquery is not executed: JSON data must use double quotes. Since String cannot be nested with double quotes, just use the escape character. The code is [{\"hello\" :\"world\"}].
The operating environment of this tutorial: windows7 system, jquery3.2.1 version, DELL G3 computer.
Recommended: jquery video tutorial
Solution to the post callback function not executing in jquery:
1. Front-end code
$.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. Backend code
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; }
Obviously there is no problem with the frontend code, and there seems to be no problem with the backend code logically. Finally, Baidu learned that there was a problem with the JSON data format of the callback, which caused the callback The function has been unable to be executed. It turns out that JSON data must use double quotes!
我的:{'hello':'world'} 标准:{"hello":"world"}
Since String cannot be used in nested double quotes, we can use escape characters
{\"hello\":\"world\"}
Related free learning recommendations: javascript(Video)
The above is the detailed content of What should I do if the post callback function in jquery does not execute?. For more information, please follow other related articles on the PHP Chinese website!