jquery Ajax asynchronous request receive return JSON data instance _jquery

Source: Internet
Author: User

jquery Ajax asynchronous request receive return JSON data method Setup is simple, one is the server handler is to return the JSON data, the other is the AJAX send settings datatype set to JSONP format data or JSON format can.

The code example is as follows:

Copy Code code as follows:

$ (' #send '). Click (function () {
$.ajax ({
Type: "Get",
URL: "a.php",
DataType: "Jsonp",
Success:function (data) {
$.each (Data.items, function (I, item) {
$ ("if (i = = 3) {
return false;
}
});
}
});
});

The $.ajax method is as follows:

Copy Code code as follows:

$.ajax ({
Type: "POST",
url:ctxroot+ ' Folderaction!saveinformsetting.action ',
Data: ' jsonstr= ' + inform_settingliststr,
DataType: "JSON",
Complete:function (data) {
To do something here, assume that the returned JSON data has the attribute name in it.
Sometimes you can directly data.name or data[' name ' to access
But sometimes, you have to go through the var jsondata = eval ("+data.responsetext+"), you can access through Jsondata.name, and in this case, you need to be complete rather than success
}
});
$.ajax (Options)

This is the most fundamental jquery Ajax method, with only one parameter options, which contains information about the request information and the callback function. The parameter contents are key:value and are optional.

The syntax is as follows:

$.ajax ({options});
URL: (string) to send the requested address, either a server page or a WebService action.
Type: (string) Request method, post or get
Data: (object) When sending a request to the server. is a key:value pair form, such as: {name: "Grayworm", Sex: "Male"}, if it is an array {works:["Work1", "Work2"]}
DataType: (string) The data type expected to be returned. Xml,html,json,text, etc.
Beforesend: (Function) is triggered before an AJAX request is sent, and if returned false cancels the request. If an asynchronous request needs to display a GIF animation, you should set the corresponding visible here.

PS: Here again for you to recommend a few more practical JSON online tools for your reference to use:

Online JSON code inspection, inspection, landscaping, formatting tools:
Http://tools.jb51.net/code/json

JSON Online formatting tool:
Http://tools.jb51.net/code/jsonformat

Online Xml/json Mutual Conversion tool:
Http://tools.jb51.net/code/xmljson

JSON code online Format/beautify/compress/edit/Convert tools:
Http://tools.jb51.net/code/jsoncodeformat

Online JSON compression/escape tool:

Http://tools.jb51.net/code/json_yasuo_trans

C language Style/html/css/json code formatting Landscaping tool:
Http://tools.jb51.net/code/ccode_html_css_json

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.