Join 3,425 readers in helping fund MetaFilter (Hide)


Why doesn't Ajax work on my server?
October 30, 2010 5:57 PM   Subscribe

When I upload this W3Schools Ajax example to my own web hosting, it doesn't work. Why?

The example works fine when I try it on the W3Schools website. But if I copy the Ajax code (the whole section of code in the lefthand panel) into a separate HTML file and upload that to my web hosting, the page loads fine but the Ajax doesn't work - i.e. when I click the button, nothing happens.

Is there something obvious I'm missing about how to get Ajax working?
posted by EndsOfInvention to Computers & Internet (6 answers total) 3 users marked this as a favorite
 
Did you also upload the "ajax_info.txt" file to the same directory?

Debugging tools like Firebug will show you why a script is failing and libraries like jQuery make these types of calls easier.
posted by null terminated at 6:09 PM on October 30, 2010


Did you also copy over the file "ajax_info.txt," which is what the script wants to insert into your page when you press the button? It should be in the same directory as the HTML file you made.

You can see the reference to it in this line:
xmlhttp.open("GET","ajax_info.txt",true);

posted by bcwinters at 6:09 PM on October 30, 2010


Did you also upload the "ajax_info.txt" file to the same directory?

Forgot to mention that yes, I did.
posted by EndsOfInvention at 6:13 PM on October 30, 2010


Ah, Firebug is great. Helped me figure out the problem: it wasn't finding the file as I'd named it wrong. D'oh.
posted by EndsOfInvention at 6:23 PM on October 30, 2010


To amplify what null terminated said, I am a reasonably good professional web developer and I am utterly handicapped without Firebug and jQuery.

Firebug simply opens your eyes to how a page actually executes. In this example you're citing, the Firebug "Net" tab would show you the attempted GET request, including request and response headers and the content body. It's like turning on the lights in a dark room. Meanwhile, writing AJAX glue using straight up raw Javascript is the web equivalent of assembly language. It's perfectly possible, but it's onerous enough compared to using an API like jQuery that (in the opinion of all the web devs I hang out with) you should use an API in all but the most nuanced cases. Here's a jQuery AJAX GET.
posted by mindsound at 6:31 PM on October 30, 2010


Just popping in to say what mindsound said.
posted by Artw at 1:35 PM on October 31, 2010


« Older Is our peed-on mattress salvag...   |  How can we get my grandma from... Newer »
This thread is closed to new comments.