This forum is now read-only. Please use our new forums at discuss.codecademy.com.

How to use APIs with JavaScript Forum

View Course » View Exercise

455 points
51fc5af280ff33e59a001a03_965662330
Submitted by
jjy
about 4 years ago

What is going on?!

//This is what I put as my answer and I receive the output 200 instead of 404:
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://www.codecademy.com/doesnt_exist", false);
xhr.send();
// Add your code below!
console.log(xhr.status)


7 votes

permalink

someone named themself doesntexist so http://www.codecademy.com/doesntexist has become the url to their profile page. Change xhr.open("GET", "http://www.codecademy.com/doesnt_exist", false); to something like xhr.open("GET", "http://www.codecademy.com/doesnt_exist51f68f4f1684", false); which you can be sure doesn't exist.

805 points
Picture
Submitted by
RaBind
about 4 years ago

4 Comments

51540e77784bbd8d5d000aa3_690552298 Shieh Min Kwai about 4 years ago

I had the same problem,and thank you for solving it.And I also want to know how it works . Can you explain it for me? Thanks!!!

Picture RaBind about 4 years ago

visit http://www.codecademy.com/doesnt_exist and you can see that someone named, themselves "doesntexist" making their profile page "http://www.codecademy.com/doesntexist", so the page actually exists now. That's why it returns 200 instead of 400.

520a4722f10c60998d002ae7_771003059 Philip Sagra about 4 years ago

Good catch @RaBind. I shoulda noticed it when it returned 200, OK. It means that the page does exist.

Picture Damian Saunders about 4 years ago

Phew! Thanks for that…I was going nuts