133
rated 0 times
[
135]
[
2]
/ answers: 1 / hits: 36575
/ 14 Years ago, sat, march 19, 2011, 12:00:00
I'm new to JavaScript programming. I'm now working on my Google Chrome Extension. This is the code that doesn't work... :P
I want getURLInfo
function to return its JSON object, and want to put it into resp
. Could someone please fix my code to get it work?
function getURLInfo(url)
{
var xhr = new XMLHttpRequest();
xhr.open
(
GET,
http://RESTfulAPI/info.json?url=
+ escape(url),
true
);
xhr.send();
xhr.onreadystatechange = function()
{
if (xhr.readyState == 4)
{
return JSON.parse(xhr.responseText);
}
}
}
var resp = getURLInfo(http://example.com/) // resp always returns undefined...
Thanks in advance.
More From » xmlhttprequest