Example
| The code is as follows |
Copy Code |
|
$ (' #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;
}
});
}
});
}); |
$.ajax methods such as
| code is as follows |
copy code |
|
$.ajax ({
type: "POST",
url: ctxroot+ ' folderaction!saveinformsetting.action ',
data: ' jsonstr= ' + inform_ Settingliststr,
datatype: "JSON",
complete:function (data) {
//doing something here, assuming that the returned JSON data has the name attribute
// Sometimes you can directly data.name or data[' name ' to access the
//But sometimes you have to go through the var jsondata = eval ("+ data.responsetext+ ")") before it can be accessed through jsondata.name, and in this case, it needs to be complete instead of success
});
$.ajax (options) |
It is the most fundamental jquery Ajax method, which has only one parameter options, which contains information about the request information and the callback function. The parameter contents are key:value and are optional.
Grammar:
$.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.