Home  >  Article  >  Web Front-end  >  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
WBOYOriginal
2016-05-16 16:41:591652browse

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" 
); 

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(); 
}

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

Statement:
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