Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Donnie;

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?