jQuery getJSON() 메서드

❮ jQuery AJAX 메소드

예시

AJAX 요청을 사용하여 JSON 데이터를 가져오고 결과를 출력합니다.

$("button").click(function(){
  $.getJSON("demo_ajax_json.js", function(result){
    $.each(result, function(i, field){
      $("div").append(field + " ");
    });
  });
});

정의 및 사용

getJSON() 메서드는 AJAX HTTP GET 요청을 사용하여 JSON 데이터를 가져오는 데 사용됩니다.


통사론

$(selector).getJSON(url,data,success(data,status,xhr))

Parameter Description
url Required. Specifies the url to send the request to
data Optional. Specifies data to be sent to the server
success(data,status,xhr) Optional. Specifies the function to run if the request succeeds
Additional parameters:
  • data - contains the data returned from the server.
  • status - contains a string containing request status ("success", "notmodified", "error", "timeout", or "parsererror").
  • xhr - contains the XMLHttpRequest object

❮ jQuery AJAX 메소드