jQuery getJSON()Method
Examples
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 Yourself »
Definition and Usage
The getJSON() method uses an AJAX HTTP GET request to retrieve JSON data.
Syntax
$(selector).getJSON(url,data,success(data,status,xhr))
| Parameter | Description |
|---|---|
| url | Required. Specifies the URL to which the request is sent. |
| data | Optional. Specifies the data sent to the server. |
| success(data,status,xhr) | Optional. Specifies the function to run when the request succeeds. Additional parameters:
|
Other Extensions
jQuery AJAX Methods