I am looking to store a returned value to a variable from the event handler function.
Here is the example code:
var xhr = new XMLHttpRequest();
function getData(e){
if(xhr.readyState === 4){
if(xhr.status === 200){
e = JSON.parse(xhr.response);
return e;
}
else{
return alert("Error!!");
}
}
}
var data;
xhr.addEventListener("load", function(){getData(data);},true); // want to store the result to data variable
console.log(data);