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
|