Definition and usage
The get () method loads information through a remote http get request. This is a simple GET request function to replace complex $. ajax. You can call the callback function when the request is successful. To execute a function when an error occurs, use $. ajax.
Syntax
$ (Selector). get (url, data, success (response, status, xhr), dataType)
Parameter description
The url is required. Specifies the URL of the request.
Data is optional. Specifies the data sent to the server together with the request.
Success (response, status, xhr) is optional. Specifies the function that runs when the request is successful.
Additional parameter descriptions:
Response-contains the result data from the request
Status-contains the Request status
Xhr-contains XMLHttpRequest object
DataType is optional. Specifies the expected server response data type. By default, jQuery can be intelligently judged.
Possible types include xml, html, text, script, json, and jsonp.
This function is short for Ajax functions and is equivalent:
$.ajax({ url: url, data: data, success: success, dataType: dataType});
Instance used:
PHP file (http://www.phpernote.com/test.php) that returns data ):
<? Php $ arr = array (0 => array ('name' => 'qianyuqianxun ', 'Nick' => 'qianxun ', 'Contact '=> array ('website' => 'HTTP: // www.phpernote.com'), 1 => array ('name' => 'qisha ', 'Nick '=> 'seven shares', 'email' => 'yhm @ 163.com ', 'Contact' => array ('website' => 'HTTP: // www.baidu.com '); print_r (json_encode ($ arr [$ _ GET ['id'] [$ _ GET ['field']); exit;
The client obtains the following code:
$. Get ('HTTP: // www.phpernote.com/test.php', Region id:0,field:'name', function (data) {alert ('name: '+ data); // The result is qianyuqianxun });
Or:
$. Get ('HTTP: // www.phpernote.com/test.php', response id:0,field:'contact'response, function (data) {var dataObj = eval ("(" + data + ")"); alert (dataObj. website); // The result is: http://www.phpernote.com });
Articles you may be interested in
- Jquery getJSON ($. getJSON) event usage and Analysis
- Jquery load ($. load) event usage and Analysis
- Jquery $. ajax $. post or $. get: How to submit the checkbox Value
- Solution to failure of jquery live change event under IE
- Common Values of Cache-control include private, no-cache, max-age, and must-revalidate.
- JQuery-handle the latency of a hover event
- Jquery simulates Mouse clicking events
- JQuery retrieves page close events