Jquery Getjson Example - Jquery
How to use getJSON method in jquery?
Snippet Code
This Simple jquery getjson( url, [data], [callback] ) method allows you to access json data from server using GET HTTP request. The sample jquery getjson code is given below.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type='text/javascript'>
$(document).ready(function(){
$("#click").click(function(){
$.getJSON('ajax-json.js', function(data) {
$("#name").append('<p> Name: ' data.name '</p>');
$("#gen").append('<p>Age : ' data.age '</p>');
$("#age").append('<p> Gender: ' data.gender '</p>');
});
});
});
</script>
<input type='button' id='click' value='Click Here to Get JSON Data'>
<div id='name'></div>
<div id='gen'></div>
<div id='age'></div>
ajax-json.js:
{
"name": "paul",
"gender": "male",
"age": "25"
}
Tags