Comparison of Different examples of ajax and post processing json in jQuery _ jquery-js tutorial

Source: Internet
Author: User
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

Related Article

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.