Phương thức jQuery getJSON ()
Thí dụ
Nhận dữ liệu JSON bằng cách sử dụng yêu cầu AJAX và xuất ra kết quả:
$("button").click(function(){
$.getJSON("demo_ajax_json.js", function(result){
$.each(result, function(i, field){
$("div").append(field + " ");
});
});
});
Định nghĩa và Cách sử dụng
Phương thức getJSON () được sử dụng để lấy dữ liệu JSON bằng cách sử dụng yêu cầu AJAX HTTP GET.
Cú pháp
$(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:
|