Reputation: 147
I am attempting to make an ajax call to a remote server, this is only for development purposes. I have CORS setup on my server, and as a result my response when requesting the resource through the browser looks like this.
As you can see the CORS headers are present, however my JavaScript request gets an error.
I am confused as to why my CORS headers are not present in the JavaScript request.
Upvotes: 1
Views: 325
Reputation: 943100
I am confused as to why my CORS headers are not present in the JavaScript request.
They are never present in the request. CORS headers are response headers. (Well, some CORS headers are request headers, Origin
for example, and that is in the request headers you listed).
The response had HTTP status code 401
Presumably your server side code is only going to include the Access-Control-Allow-Origin response header when it makes a 200 OK response.
Since the request was missing the cookie, it rejected it as unauthorised.
Cross-origin XHR requests need to set withCredentials
to true
in order for the browser to send or accept Cookies.
Upvotes: 1