I'm fairly new to using XMLHttpRequest
s, but I've been experimenting with the cross-origin function in Google Chrome extensions. My code works well (I am able to receive the data I need), however, I am facing issues when trying to store it within the 'response' variable.
I could really use some guidance on this.
function getSource() {
var response;
var xmlhttp;
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
response = xmlhttp.responseText;
//Data is correctly set here
}
//Still holding value here
}
//Suddenly becomes undefined here.
xmlhttp.open("GET","http://www.google.com",true);
xmlhttp.send();
return response;
}