Forum Moderators: open

Message Too Old, No Replies

XMLHttpRequestObject.responseText

         

chris0055

8:18 pm on Sep 23, 2009 (gmt 0)

10+ Year Member



Hi, I'm an absolute beginner to Javascript and ajax, and i was following this ajax tutorial on youtube who demonstrate how to create a link to google search using ajax. I follow everything but my firefox told me there is an error. The syntax is exactly the same but I have no idea why the error occurs. The error says that :

window.google undefined!

and pointing to the code:
function getData(dataSource)
{
if(XMLHttpRequestObject)
{
XMLHttpRequestObject.open("GET",dataSource);

XMLHttpRequestObject.onreadystatechange = function()
{
if(XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200)
{
eval(XMLHttpRequestObject.responseText);
}
}
XMLHttpRequestObject.send(null);
}
}

Where the evaluation eval(XMLHttpRequestObject.responseText); has the error! Any help?! Thank you so much!

whoisgregg

1:57 pm on Sep 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld, chris0055!

It may be an issue not with your script, but with how the data itself is formatted.

Could you try adding an

alert(XMLHttpRequestObject.responseText);
above your eval line to see what it is trying to eval?