Summary of Ajax asynchronous returned data formats in jquery

Source: Internet
Author: User
  1. Data Type

JS Code:

$. Post ("getmaterial. do? Method = getmaterial ", <br/> {Name: name}, <br/> function (data) {</P> <p> });

Getmaterial. do? Method = getmaterial is the request URL, and {Name: name} is the parameter passed to the background. You can use

Request. getparameter ("name"); get, data is transmitted from the background.

 

Action Code:

 

Response. setcontenttype ("text/html; charset = GBK"); <br/> printwriter out = response. getwriter (); <br/> out. println ("test ");

In this case, data is test.

 

2. XML data is returned.

JS Code:

// Post sending method <br/>/* $. post ('. /getsd. do ', STR, <br/> function (XML) {<br/> alert (XML. XML); <br/> $ ("# otherinfo" ).html ("Project name:" + $ ("proname", XML ). text () + "test pair </P> <p> image:" + $ ("testaim", XML ). text (); <br/>}, "XML ");*/

Action Code:

/* Response. setheader ("charset", "UTF-8"); <br/> out. println ("<? XML version = '1. 0' encoding = 'utf-8'?> "); <Br/> out. println ("<result>"); <br/> while (RS. next () {<br/> out. println ("<testaim>"); <br/> out. println (RS. getstring ("testaim"); <br/> out. println ("</testaim>"); <br/> out. println ("<proname>"); <br/> out. println (RS. getstring ("proname"); <br/> system. out. println (RS. getstring ("proname"); <br/> out. println ("</proname>"); <br/>}< br/> out. println ("</result> ");*/

 

 

3. Return JSON data

JS Code:

$. Getjson ('. /getsd. do ', {Ylid: Ylid}, function callback (JSON) {<br/> // alert (JSON. proname); <br/> // $ ("# otherinfo" ).html ("Project name:" + JSON. proname + "test pair </P> <p> image:" + JSON. testaim); <br/> $ ("# proname "). ATTR ("value", decodeuri (JSON. proname); <br/> $ ("# testaim "). ATTR ("value", decodeuri (JSON. testaim); <br/> });

 

 

Action Code:

/** <Br/> * return data in JSON format <br/> */<br/> jsonobject JB = new jsonobject (); <br/> while (RS. next () {<br/> system. out. println (RS. getstring ("proname"); <br/> JB. put ("testaim", java.net. urlencoder. encode (RS. getstring ("testaim"), "UTF </P> <p>-8"); <br/> JB. put ("proname", java.net. urlencoder. encode (RS. getstring ("proname"), "UTF </P> <p>-8"); <br/>}< br/> out. println (JB. tostring ());

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.