jQuery getJSON()Method

jQuery AJAX 方法jQuery AJAX Methods

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:
  • data- Contains the data returned from the server
  • status- Contains the status of the request ("success", "notmodified", "error", "timeout", "parsererror")
  • xhr- Contains the XMLHttpRequest object


jQuery AJAX 方法jQuery AJAX Methods

Other Extensions