Reference: jQuery get method
Get data from the server using a HTTP GET request.
Parameters
- URL - The URL to get the JSON data from the server.
- data - Optional JSON Object containing key / value pairs to send with the request.
- calback - Optional function that is called when the request is complete.
- type - Optional The type of data expected from the server. Default: Intelligent Guess (xml, json, script, text, html).
Callback
The callback has the following parameters:
- responseText - The HTML returned from the server if the request succeeds.
- textStatus - The status of the response.
- jqXHR - XMLHttpRequest object.
Syntax
$.getJSON(URL, data, callback, type);
Example getting HTML data
Get the viewContent.html page from the server and load the contents into the element with an id of "view".
$.get("/viewContent.html", function(data) { $("#view").html(data); });
Example getting JSON data
Get a list of employees from the server.
$.get("/employee/list", function (list) { for (var idx = 0; idx < list.length; idx++) { console.log(JSON.stringify(list[idx])); } });