Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery getJSON() method

jQuery getJSON() method

jQuery AJAX methods jQuery AJAX methods

Example

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 »


Definition and Usage

The getJSON() method retrieves JSON data using an AJAX HTTP GET request.


Syntax

$(

selector

).getJSON(

url,data,success(data,status,xhr))

Parameters Description
url Required. Specifies the URL to which the request is sent.
data Optional. Specifies the data to send to the server.
success(data,status,xhr) Optional. Specifies the function to run when the request succeeds.
 额外的参数:     
  • 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 methods jQuery AJAX methods