function getMensages(){
var xhr = new XMLHttpRequest();
xhr.open('GET', '../mensagens.php');
xhr.send();
xhr.onload=function(){
if (xhr.readyState==4 && xhr.status==200){
jsonText = xhr.responseText;
jsonObj = JSON.parse(jsonText);
}
return jsonObj;
}
}
getMensages();
console.log(jsonObj);
How do I get the jsonObj
variable out of the scope of the xhr.onload()
function and out of the getMensages()
function? When calling the function xhr.onload()
it is already returning object I want but I need the object in the variable outside the scopes.