How to get and parse the JSON data in jQuery

Getting and parsing JSON data in jQuery:

$.getJSON(URL, [data], [callback]);

URL - server side resource communicated via GET method.

data - an object whose properties as name/value pairs to be appended as a query string with the URL.

callback - a function will be invoked and can parses the resulting JSON string as the first parameter and second parameter for status.

Example jQuery to get JSON data and parses in callback function:

<script type="text/javascript" language="javascript">
$(document).ready(function(){

  $('#btnResult').click(function(event){
    $.getJSON('/result.json', function(student){
      $('#result').html('<p>ID:'+student.id+'</p>');
      $('#result').append('<p>Name: '+student.name+'</p>');
      $('#result').append('<p>Grade: '+student.grade+'</p>');
    });
  });

});

</script>

Privacy Policy  |  Copyrightcopyright symbol2020 - All Rights Reserved.  |  Contact us   |  Report website issues in Github   |  Facebook page   |  Google+ page

Email Facebook Google LinkedIn Twitter
^