Hi there I am trying to return an object from the loadData function but I get "obj is not defined" in FF and "Uncaught ReferenceError" in chrome.I read that if you declare a variable without prefix "var it is assumed to be global"the scope of "obj" should be global and should return me the data from the json response.I have no idea where I am going wrong I am new to Javascript.Thanks for all the help.
function loadData()
{.....
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
personInfo=xmlhttp.responseText;
obj = JSON.parse(personInfo);
alert(obj[2].name);
}
};
return obj;//"obj is not defined" in FF and "Uncaught ReferenceError" in chrome
}
<h2>AJAX</h2>
<button type="button" onclick="loadData()">Request data</button>
<div id="myDiv"></div>
....