Data processing in the AJAX request of jquery

Source: Internet
Author: User

Front Desk (1) JS The Ajax method that made the request
1 $.ajax ({2URL: "*.do",//url is the path to be requested3Type: "Get",//type is the type of the HTTP request and the value is "get" or "POST"4Data: "key=" + value+ "&key=" + value+ "&key=" +value,/* data is submitted at the time of request, can be obtained by Request.getparameter () in the background
, this can be a URL to the way, you can also put a JavaScript object such as {Key:value,key:value,...} * /5DataType: "JSON",//here if the background is a JSON string, and the foreground wants to use the JSON string as a JavaScript object, the datatype here must be "JSON", otherwise JS will be treated as a normal string6Successfunction(data) {//Here is the callback method executed when the request succeeds, not the callback executed when the operation of the background method succeeds7 processing data returned from the background8 },9Errorfunction(XMLHttpRequest, Textstatus, Errorthrown) {//This is the callback that is executed when the request fails Ten alert (XMLHttpRequest); One alert (textstatus); A alert (errorthrown); - } -});

(2) Usually if you just want to know whether the background execution is successful or not, you do not need to use the JSON string, only need to use Response.getwriter (). Print () outputs a character that represents the result of the execution; However, sometimes you want to pass the background data such as a list containing JavaBean to the foreground, you can use the JSON string; The main method in the background controller method when using JSON string

1 // object is any Java object, such as Java bean,persistent Entity,pojo 2 sonobject jsonobject = Jsonobject.fromobject (object); 3 String jsonstr=jsonobject. toString (); 4 response.getwriter (). print (JSONSTR); 5 return null;

(3) Jar packages that are dependent on retrieving JSON strings in the background

Data processing in the AJAX request of 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.