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?
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?
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:
posted by bcwinters at 6:09 PM on October 30, 2010
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
Response by poster: 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
Forgot to mention that yes, I did.
posted by EndsOfInvention at 6:13 PM on October 30, 2010
Response by poster: 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
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
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
This thread is closed to new comments.
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