jQuery getJSON() method
jQuery provides getJSON() method for getting JSON data from a service.
This is a shortcut for the jquery Ajax function.
This method is used to get JSON data using an AJAX HTTP GET request.
getJSON Syntax
jQuery.getJSON( url [, data ] [, success ] )
Here,
url : string containing the URL to which the request is sent.
data : object or string that is sent to the server with the request.
success : callback function that is executed if the request succeeds
jQuery getJSON example
<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> <script> $(document).ready(function() { var url = 'https://api.github.com/users/topjavatutorial/repos'; $.getJSON(url, function(response) { document.getElementById("github_repositories").innerHTML = response[0].html_url + " <br/>" + response[1].html_url + " <br/>" + response[2].html_url; }); }); </script> </head> <body> <h2>jQuery getJSON() example</h2> <p id="github_repositories">JSON retrieved from AJAX call will be shown here</p> </body> </html>
© 2016, https:. All rights reserved. On republishing this post, you must provide link to original post