The reason why the callback is not entered after Jquery Post processing and the solution

  • 2020-03-30 03:31:25
  • OfStack

Today, I did a simple adding data. I passed the Json data to the background of the Jsp through the Post method of Jquery. However, I did not enter the callback function after processing.


$.post("addGs.do","x=" + JSON.stringify(x) 
,function(d){ 
alert(' successful '); 
} 
,"json" 
); 

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

I can't help it, but look at the Jquery API, and say if the last argument is Json, you want to return data in Json format,

Is it possible that the returned Json is not standard ?

Remember that Json now requires you to use double quotes for Key and Value,

Change the code right now


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

This time it worked.

The Post method in Json has to be in a strict Json format to enter a callback, which is not required in Text


Related articles: