Getting JSON data using jQuery getJSON method

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 ] ) 


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


  $(document).ready(function() {
    var url = '';
    $.getJSON(url, function(response) {
      document.getElementById("github_repositories").innerHTML = response[0].html_url + " <br/>" + response[1].html_url + " <br/>" + response[2].html_url;
  <h2>jQuery getJSON() example</h2>

  <p id="github_repositories">JSON retrieved from AJAX call will be shown here</p>




© 2016, https:. All rights reserved. On republishing this post, you must provide link to original post

Leave a Reply.. code can be added in <code> </code> tags