var persons; $(function () { $.getJSON("person.json", function(data){ persons = JSON.stringify(data); console.log("This is inside: "+ persons); }); console.log("This is outside" + persons); } getJSONData(); });
This is outside: undefined This is inside: [{"name":"user1","gender":"male"},{"name":"user2"},{"gender":"female"}]
var persons; function getJSONData() { $.getJSON("person.json", function(data){ persons = JSON.stringify(data); console.log("This is inside: "+ persons); }); } getJSONData(); $(function () { console.log("This is outside: " + persons); });
$.getJSON
$.getJSON("person.json", function(json) { console.log(json); // this will show the info it in firebug console });
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)