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