I'm making an AJAX call from my popup.html
like so..
chrome.extension.sendRequest(
{
req: "send",
url: requrl
},
function(response)
{
console.log("RESPONSE:" + response.reply);
});
This code goes to the following case in background.html...
case "send":
sendResponse({
reply: send(request.url)
});
break;
which in turn calls the following...
function send(uri)
{
var xhr = new XMLHttpRequest();
xhr.open("POST",uri,true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
xhr.onreadystatechange = function (send){
if(xhr.readyState == 4){
return xhr.responseText;
}
}
xhr.send(null);
}
My problem is that my code is returning undefined
before send()
has a chance to respond. How can I make my code wait for a response? I need to keep this call asynchronous because I need the UI not frozen to display a progress dialog.