0

I have a webpage that calls a rest endpoint using Ajax. I want to print out the http status code when my rest call errors. When the rest endpoint returns a 500, I can see 500 being printed. But when the call returns a 404, then the value 0 is printed. thrownError is blank.

I'm new to Javascript but can anyone tell me why 0 would be printed? It's only for 404s. I've tested 5xx and they are all fine.

$.ajax({
    type: 'GET',
    url: 'mysite.com',
    crossDomain: true
    success: function (data) {
      console.log(data);
    },
    error: function (xhr, ajaxOptions, thrownError) {
      console.log(xhr.status);
    },
  });
TheCoder
  • 8,413
  • 15
  • 42
  • 54
  • Is it just on your site or a 404 error anywhere? I suspect a configuration issue with your web server. – Lorenz Meyer Aug 08 '17 at 20:17
  • @LorenzMeyer The web page and the rest end point are both hosted on the same web server. – TheCoder Aug 08 '17 at 21:08
  • Kind of puzzling what you're saying: *"`status` `0` when it's `404`"* you get either one or the other, but I'm guessing you get `404` when you access the link directly in the browser ?? – user10089632 Nov 11 '17 at 06:42
  • [Check this out](https://stackoverflow.com/questions/872206/http-status-code-0-what-does-this-mean-for-fetch-or-xmlhttprequest#answer-14507670) – user10089632 Nov 11 '17 at 06:42

0 Answers0