The difference between Ajax and post processing JSON in jquery

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.