Home > Web Front-end > JS Tutorial > Reasons and solutions for not entering callback after Jquery Post processing_jquery

Reasons and solutions for not entering callback after Jquery Post processing_jquery

WBOY
Release: 2016-05-16 16:41:59
Original
1725 people have browsed it

Today I will do a simple job of adding data, using Jquery’s Post method to transfer Json data to the Jsp background. After processing, it does not enter the callback function.

$.post("addGs.do","x=" + JSON.stringify(x) 
,function(d){ 
alert('成功'); 
} 
,"json" 
); 
Copy after login

Through FF debugging, it was found that the returned data is normal, 200Ok,

No way, look at the Jquery API again, it says that if the last parameter is Json, the returned data is required to be in Json format,

Is it possible that the returned Json is not standard?

Remember that Json now generally requires double quotes for Key and Value,

Change the code immediately

try{ 
d.add(gs); 
out.println("{\"s\":\"ok\"}"); 
} 
catch(Exception e) 
{ 
out.println("{\"s\":\"err\"}"); 
e.printStackTrace(); 
}
Copy after login

Finally succeeded this time.

In Json mode, the Post method must use strict Json format to enter the callback. If you use Text mode, there is no such requirement

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