Home > Web Front-end > JS Tutorial > What should I do if the jquery $.post method does not execute?

What should I do if the jquery $.post method does not execute?

coldplay.xixi
Release: 2020-11-30 16:13:32
Original
2340 people have browsed it

The solution to the problem that the jquery $.post method is not executed: Set the returned data to json data, and the code is [out.print(JSONObject.fromObject(result));].

What should I do if the jquery $.post method does not execute?

The operating environment of this tutorial: windows7 system, jquery3.2.1 version. This method is suitable for all brands of computers.

Solution to the problem that the jquery $.post method does not execute:

About the problem that JQuery’s post callback function does not execute

The front-end post callback function is No execution, after setting the breakpoint debug or directly skip the execution

Error demonstration:

Background code

@RequestMapping(value = "login")
public void CheckUserAccount(@RequestParam("account")String account, HttpServletResponse response) throws IOException{
JSONObject json_account = JSONObject.fromObject(account);
int username = (Integer)json_account.get("username");
String password = json_account.getString("password");
logger.info("username = " + username + " password = " + password);
int status;
status = checkUserAccountService.IsCorrect(username, password);
Map<String, Object> result = new HashMap<String, Object>();
Map<String, String> info_json = new HashMap<String, String>();
if(status == 1){
info_json.put("status", "success");
}else if(status == 0){
info_json.put("status", "errorpassword");
}else{
info_json.put("status", "noexitaccount");
}
result.put("info", info_json);
JSONObject json_object = JSONObject.fromObject(result);
response.setContentType("text/json; charset=utf-8");
response.setHeader("Cache-Control", "no-cache");
PrintWriter out = response.getWriter();
out.print(result);
out.flush();
out.close();
logger.info("验证结果是" + ((Map<String, String>)(result.get("info"))).get("status"));
Copy after login

The key sentence is:

response.setContentType("text/json; charset=utf-8");

The data returned here is set to json data, but out.print(result);The output here is A Map, so the front end cannot recognize any data. As a result, the callback function is skipped and not executed (because the callback function only executes json data)

Correct demonstration:

Change to: out .print(JSONObject.fromObject(result));

is fine.

Related free learning recommendations: javascript (video)

The above is the detailed content of What should I do if the jquery $.post method 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