Ajax JSON data Asynchronous request method

Source: Internet
Author: User

In JQuery 1.2, you can load JSON data for other domains, such as "myurl?callback=?", by using a callback function in JSONP form. Will jQuery be replaced automatically? To the correct function name to execute the callback function. Note: The code after this line will execute before the callback function executes.

Instance

$.ajax ({
Type: "Get",
DataType: "JSON",
URL: "<%=basepath%>actionsmuser.do?method=getusermsgbyuserid",
Data: "Userid=" +userid,
Success:function (msg) {
var data = eval ("(" +msg.responsetext+ ")");
Alert ($ ("#userName"). Val ());
$ ("#userName"). Val (Data[0].username);

}
});

Detailed description
This function is shorthand for Ajax functions, equivalent to:

$.ajax ({
Url:url,
Data:data,
Success:callback,
Datatype:json
});

Data sent to the server can be appended to the URL as a query string. If the value of the data parameter is an object (map), it is converted to a string and URL-coded before being appended to the URL.

Getjson

$.getjson (url,function (data) {
if (data!=null && data!= "") {
$ ("#userIdInput"). Val (Data[0].userid);
$ ("#userNameInput"). Val (Data[0].username);
$ ("#menusIdInput"). Val (Data[0].menusid);
$ ("#depIdInput"). Val (data[0].depid);
$ ("#isValidInput"). Val (Data[0].isvalid);
$ ("#userIdInput"). attr ("Disabled", true);
}

});

Reference table

Grammar

Jquery.getjson (URL,data,success (DATA,STATUS,XHR))

Parameters Description
Url Necessary. Specify which URL to send the request to.
Data Optional. Specify the data to be sent to the server along with the request.
Success (DATA,STATUS,XHR)

Optional. A function that is required to run when a request succeeds.

Additional parameters:

  • Response -Contains the result data from the request
  • Status-Contains the state of the request
  • xhr -Contains XMLHttpRequest objects

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.