jQuery get() method
Example
Send an HTTP GET request to a page and retrieve the result:
$
(
"
button
"
)
.
click
(
function
(
)
{
$.
get
(
"
/try/ajax/demo_test.php
"
,
function
(
data
,
status
)
{
alert
(
"
Data:
"
data
"
\n
Status:
"
status
)
;
}
)
;
}
)
;
Try it »
Definition and Usage
The $.get() method loads data from the server using an HTTP GET request.
Example
Request "test.php", but ignore the returned result:
$.get("test.php");
Request "test.php" and send some extra data with the request (ignore the returned result):
$.get("test.php", { name:"Donald", town:"Ducktown" });
Request "test.php" and pass an array of data to the server (ignore the returned result):
$.get("test.php", { 'colors[]' : ["Red","Green","Blue"] });
Request "test.php" and alert the result of the request:
$.get("test.php", function(data){
alert("Data: " + data);
});
Syntax
$.get(
URL,data,function(data,status,xhr),dataType)
| Parameters | Description |
|---|---|
| URL | Required. Specifies the URL you want to request. |
| data | Optional. Specifies the data to send to the server along with the request. |
| function(data,status,xhr) | Optional. Specifies the function to run when the request succeeds. |
额外的参数:
- "xml" - An XML document
- "html" - HTML as plain text
- "text" - A plain text string
- "script" - Runs the response as JavaScript and returns it as plain text
- "json" - Runs the response as JSON and returns it as a JavaScript object
- "jsonp" - Loads a JSON block using JSONP, adding a "?callback=?" to the URL to specify the callback
jQuery AJAX methods