Javascript examples for jQuery Method and Property:getJSON
The getJSON() method gets JSON data using an AJAX HTTP GET request.
$.getJSON(url,data,function(data,status,xhr))
Parameter | Require | Description |
---|---|---|
url | Required. | url to send the request to |
data | Optional. | data to be sent to the server |
success(data,status,xhr) | Optional. | the function to run if the request succeeds |
success(data,status,xhr) parameters:
The following code shows how to Get JSON data using an AJAX request, and output the result:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $.getJSON("demo_ajax_json.js", function(result){ $.each(result, function(i, field){ $("div").append(field + " "); });//from www . j a v a 2s . com }); }); }); </script> </head> <body> <button>test</button> <div></div> </body> </html>