Using Xmlhttprequest In A Google Chrome Extension
I started making this simple google chrome extension in javascript. And in the beginning of the code I have the following: var req = new XMLHttpRequest(); req.open( 'GET',
Solution 1:
how about something like this
var request = newXMLHttpRequest();
if (request == null){
alert("Unable to create request");
}else{
var url = "http://www.ldoceonline.com/dictionary/manga";
request.onreadystatechange = function()
{
if(request.readyState == 4)
{
LDResponse(request.responseText);
}
}
request.open("GET", url, true);
request.send(null);
}
functionLDResponse(response)
{
// do stuff with the response
}
Of course this is all assuming that they are giving you valid data back ie XML or json
Solution 2:
On this line:
req.onreadystatechange(alert(req.readyState));
alert()
is being called straight away, which I'm sure isn't your intention. It seems that you want to wait for the onreadystatechange
event to fire and then alert the readyState
. If that's the case then try this:
req.onreadystatechange = function() {
alert(req.readyState);
};
And don't forget req.send(null)
!
Post a Comment for "Using Xmlhttprequest In A Google Chrome Extension"