Receive return JSON data via jquery's Ajax asynchronous request

Source: Internet
Author: User

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

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.