jQuery getJSON() method
Example
Use an Ajax request to get JSON data and output the result:
$
(
document
)
.
ready
(
function
(
)
{
$
(
"
button
"
)
.
click
(
function
(
)
{
$.
getJSON
(
"
demo_ajax_json.js
"
,
function
(
result
)
{
$.
each
(
result
,
function
(
i
,
field
)
{
$
(
"
div
"
)
.
append
(
field
"
"
)
;
}
)
;
}
)
;
}
)
;
}
)
;
Try it »
Definition and Usage
The getJSON() method retrieves JSON data using an AJAX HTTP GET request.
Syntax
$(
selector
).getJSON(
url,data,success(data,status,xhr))
| Parameters | Description |
|---|---|
| url | Required. Specifies the URL to which the request is sent. |
| data | Optional. Specifies the data to send to the server. |
| success(data,status,xhr) | Optional. Specifies the function to run when the request succeeds. |
额外的参数:
jQuery AJAX methods