Reference: jQuery getJSON method

Get JSON data using an AJAX HTTP GET request.

Parameters

  1. URL - The URL to get the JSON data from the server.
  2. data - Optional JSON Object containing key / value pairs to send with the request.
  3. calback - Optional function that is called when the request is complete.

Callback

The callback has the following parameters:

  1. responseText - The HTML returned from the server if the request succeeds.
  2. textStatus - The status of the response.
  3. jqXHR - XMLHttpRequest object

Syntax

$.getJSON(URL, data, callback);

Example

Get a list of employees from the server.

$.getJSON("/employee/list", function (list) {
  for (var idx = 0; idx < list.length; idx++) {
    console.log(JSON.stringify(list[idx]));
  }
});
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License