Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript AJAX Basics (retiring) Programming AJAX AJAX Callbacks

I am getting the contents of the index.html when I put in a non-existing filename.

I can't figure it out, but when I changed the filename for the ajax request, instead of it triggering the error codes it returned 200 and returned the contents of index.html, even when that is not what I put.

Ken Alger
Ken Alger
Treehouse Teacher


Would you mind posting your code?

Thanks, Ken

2 Answers

Andrew Shook
Andrew Shook
31,709 Points

Donnie Reese, can't be 100% sure without seeing your code and knowing a few other thing, but I think your problem has to do with the way the server is handling the http requests. If the file you are requesting is in the same folder are the index.html, then the server may be falling back to the index.html when it can't find the correct file. Not sure if this will help, but If you post you code I'm sure someone here will be able to help you.

Vance Rivera
Vance Rivera
18,322 Points

Having the same issue here as well. Not sure exactly why. I added the condition to check the if request status is 200 and I changed my request open to get a page that is not defined/valid but my code never gets falls into the else block which would display an alert box with the statusText. Instead what I get is my responseText is my index page. So I took a look at the javascript console and noticed that the response status is equal to 200 and the statusText is "ok". Not sure why.....should have been a file not found alert. Any explanations would be great. Is there another way to check the status of the response?