Home > Web Front-end > JS Tutorial > What should I do if the post callback function in jquery does not execute?

What should I do if the post callback function in jquery does not execute?

coldplay.xixi
Release: 2023-01-04 09:37:57
Original
2743 people have browsed it

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\"}].

What should I do if the post callback function in jquery does not execute?

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');
Copy after login

2. Backend code

public String deleteUser() {
        int count = userDao.deleteUser(model.getUid());
        try {
            PrintWriter writer = response.getWriter();
            if(count<=0) writer.write("{&#39;errorMsg&#39;:&#39;删除失败&#39;}");
            else writer.write("{&#39;success&#39;:&#39;删除成功&#39;}");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
Copy after login

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!

我的:{&#39;hello&#39;:&#39;world&#39;}
标准:{"hello":"world"}
Copy after login

Since String cannot be used in nested double quotes, we can use escape characters

{\"hello\":\"world\"}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template