The post method is used to process json data of ajax callback. If the result cannot be obtained, json is returned in the background. The solution to this problem is as follows, if you encounter this problem, you can take a look at the user comments made in the portal recently. It has not been easy to use jquery for a long time. I didn't expect the hacker to use the post method to process json data of ajax callback, json is returned in the background. Unexpectedly, I had to wait for several hours for such a small problem. Then I processed the ajax method and found that the original post method callback json must be eval, the ajax method does the default processing. Please be careful.
Function haha () {jQuery. post ("addComment! Comment. action ", function aa (data) {data = eval (data); // the POST method is required. The ajax method automatically processes alert (data [0]. userId); alert (data [0]. userName) ;}, "json"); jQuery. ajax ({type: "post", url: "addComment! Comment. action ", dataType:" json ", success: function aa (data) {alert (data [0]. userId); alert (data [0]. userName );}});}
Background:
The Code is as follows:
Public String comment (){
Try {
User u = new User ("user", "koko ");
List = new ArrayList ();
List. add (u );
// Map. put ("id", userId );
// JSONObject jb = JSONObject. fromObject (list); // name: "+ userName + ",
// Info = jb. toString ();
System. out. println (list );
}
Catch (Exception e ){
E. printStackTrace ();
}
Return SUCCESS;
}
Configuration:
The Code is as follows:
List