1

How can i access status codes in the "fail" jquery callback function. The jXhr reports a code of 0. The textStatus is "error". When making the request using curl there is a json response body present and the status code is set correctly. See below.

< HTTP/1.1 401 Unauthorized
HTTP/1.1 401 Unauthorized
< Server: nginx/1.10.0 (Ubuntu)
Server: nginx/1.10.0 (Ubuntu)
< Date: Tue, 09 Aug 2016 01:39:03 GMT
Date: Tue, 09 Aug 2016 01:39:03 GMT
< Content-Type: application/json
Content-Type: application/json
< Content-Length: 42
Content-Length: 42
< Connection: keep-alive
Connection: keep-alive

< 
* Connection #0 to host api.somedomain.com left intact
{"status": "error", "msg": "unauthorized"}

Am i missing something here. This is not a jsonp request. The server sets the: Access-Control-Allow-Origin appropriately during the preflight OPTIONS request before this GET request in question. The parent domain is the same, only the subdomains are different.

The backend is using python 3 with Bottle

The statusCode with the 401 callback does not get triggered and the error callback gets triggered but the status code is set to 0, also the complete callback reports status code of 0. The other questions do not solve my issue.

Dan
  • 2,209
  • 3
  • 23
  • 44
  • Possible duplicate of [How do I get the HTTP status code with jQuery?](http://stackoverflow.com/questions/2955947/how-do-i-get-the-http-status-code-with-jquery) – Karin Aug 09 '16 at 02:23
  • the statusCode with the 401 callback does not get triggered and the error callback gets triggered but the status code is set to 0, also the complete callback reports status code of 0 – Dan Aug 09 '16 at 02:30

1 Answers1

1

Even though the preflight OPTIONS call was successful and had all the cross domain related headers set. The subsequent GET call has to have the following header set as well: Access-Control-Allow-Origin

I added it and that fixed the issue. Hopefully this helps someone out there in the future.

Dan
  • 2,209
  • 3
  • 23
  • 44