English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

jQuery getJSON() Method

jQuery AJAX Methods

The $ .getJSON() method uses GET HTTP requests to load JSON formatted data from the server.

Syntax:

$.getJSON(URL, data, callback)

Instance

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‹/›

Parameter Value

ParametersDescription
URLSpecify 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:

  • data-Contain the result data from the request

  • status-Contain the status of the request ("success", "notmodified", "error", "timeout", "parsererror")

  • xhr-Contain an XMLHttpRequest object

jQuery AJAX Methods