jquery Ajax asynchronous request receive return JSON data

Source: Internet
Author: User

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.

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.