Hi friend I'm learing hoq jSON works I create file named demo_ajax_json.js which has following code
[
{
"firstName": "John",
"lastName": "Doe",
"age": 25
},
{
"firstName": "SAM",
"lastName": "Doe",
"age": 36
},
{
"firstName": "MAX",
"lastName": "Doe",
"age": 55
}
]
I'm tryiung to fetch firstName and age only. I wrote following code
function json(){
$.getJSON( "demo_ajax_json.js", function( data ) {
var items = [];
$.each( data, function( firstName, age) {
$("div ul").append( "<li id='" + firstName + "'>" + age+ "</li>" );
});
});
}
$(document).ready(function(){
$("button").click(function(){
json();
});
});
And this code giving me this
[object Object]
[object Object]
[object Object]
Plz help guys how to get this done.
Thanks in advance