jquery's Ajax asynchronous request to receive the return JSON data method setting is simple, one is that the server handler returns the JSON data, and the other is that the AJAX Send settings datatype set to either JSONP format data or JSON format.
The code examples are as follows:
$('#send'). Click (function () {$.ajax ({type:"GET", URL:"a.php", DataType:"Jsonp", Success:function (data) {$.each (Data.items, function (I, item) {$ (""). attr ("src", ITEM.MEDIA.M). AppendTo ("#resText"); if(i = =3) { return false; } }); } });});
The $.ajax method is as follows:
$.ajax ({type:"POST", Url:ctxroot+'folderaction!saveinformsetting.action', Data:'jsonstr='+inform_settingliststr, DataType:"JSON", Complete:function (data) {//do something here, assuming that the JSON data returned has the name attribute//Sometimes you can go directly to Data.name or data[' name '] to access//Sometimes, however, you have to pass the var jsondata = eval ("+data.responsetext+") to access it through Jsondata.name, and in this case it needs 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 to form and are optional.
The syntax is as follows:
$.ajax ({options});
URL: (string) The address of the sending request, which can be a server page or a WebService action.
Type: (string) request mode, post or get
Data: (object) When sending requests to the server. is key:value to form, such as: {name: "Grayworm", Sex: "Male"}, if array {works:["Work1", "Work2"]}
DataType: (String) The expected return data type. Xml,html,json,text, etc.
Beforesend: (Function) is triggered before an AJAX request is sent, and if it returns false, the request is canceled. If an asynchronous request needs to display an animated GIF, you should set the corresponding visible here.
Receive return JSON data via jquery's Ajax asynchronous request