Recently in the user review of the portal, for a long time did not use jquery just use it, did not expect to steal work with the Post method to deal with the Ajax callback JSON data, the dead and alive, the background is JSON returned. Behold such a small problem hung me for several hours, and then I Ajax method processing, incredibly OK, a comparison found that the original post method callback JSON must be eval, and the Ajax method did the default processing. I hope you are careful ...
function haha () {jquery.post ("addcomment!comment.action", function AA (data) { data = eval (data);//post method must be added, The Ajax method automatically handles 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:
Public String Comment () {try{user u = New User ("User", "Koko"), List = new arraylist<user> (); 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:
<package name= "Ajax" extends= "Json-default" ><action name= "AddComment" class= " Org.test.action.CommentAction "><result type=" json "> <param name=" root ">list</param>< /result></action> ...
The difference between Ajax and post processing JSON in jquery