English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The $ .getJSON() method uses GET HTTP requests to load JSON formatted data from the server.
$.getJSON(URL, data, callback)
Request the demo.json file and output the data:
$("button").click(function(){ $.getJSON("demo.json", function(data){ $("#output").html(data.name); }); });Test to see‹/›
This example loops through the requested data and appends it to the p with id="output":
$("button").click(function(){ $.getJSON("demo.json", function(data){ $.each(data, function(key, val){ $("#output").append(key + : " + val + "<br>"); }); }); });Test to see‹/›
Parameters | Description |
---|---|
URL | Specify the URL you want to request |
data | (Optional) Specify a plain object or string to be sent along with the request to the server |
callback | (Optional) Specify a callback function to be executed after the request is successful Parameters:
|