1

I am making AJAX request with javascript fetch, but it is only making OPTIONS call and not making further call. Weirdest thing is that the response header is just fine and $.ajax is working as expected.

Here is the response header on OPTIONS call.

HTTP/1.1 200 OK
Content-Length: 0
Server: Microsoft-IIS/8.0
Access-Control-Allow-Origin: http://localhost:5000
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: authorization
X-Powered-By: ASP.NET
Access-Control-Max-Age: 30000000
Set-Cookie: XXXXXXXXXXXX
Date: Wed, 16 Aug 2017 00:57:48 GMT

And here is fetch header set.

mode: 'cors',
credentials: 'include',
headers: {
    Authorization: 'Bearer Token'
}
sideshowbarker
  • 81,827
  • 26
  • 193
  • 197
João Silva
  • 101
  • 2
  • 4
  • because it's a CORS request preflight check - see [documentation on CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS) - odd that you can't see the GET/POST (whichever you are actually doing) request though – Jaromanda X Aug 16 '17 at 01:08
  • 1
    You sure it's not making any more calls? Because you state it's working--so it must be making the other call. – Dave Newton Aug 16 '17 at 01:12
  • I don't see it on network tab... @DaveNewton – João Silva Aug 16 '17 at 01:16
  • @JaromandaX I already took look at CORS doc again, but it doesn't help. – João Silva Aug 16 '17 at 01:19
  • You can chain the actual request to the response of `OPTIONS` request – guest271314 Aug 16 '17 at 01:20
  • how do I do it @guest271314 ? – João Silva Aug 16 '17 at 01:21
  • See [Why does Fetch API Send the first PUT request as OPTIONS](https://stackoverflow.com/q/42311018/) `fetch("url", {method:"OPTIONS"}) .then(response => response.headers) .then(_headers => (Array.from(_headers.entries(), h => console.log(h)), // check expected headers here fetch(url))).catch(err => console.error(err)).then(response => response.text()).then(text => //do stuff)` – guest271314 Aug 16 '17 at 01:22
  • thanks @guest271314 I think it gets the response. Looks like it's chrome issue that it is not showing on network tab. – João Silva Aug 16 '17 at 01:37

1 Answers1

4

I was having the same problem today and I found out that my POST call was actually happening, it just didn't show up under the Chrome XHR network filter. By changing the filter to 'all', I was able to see the request.

Borre Mosch
  • 4,404
  • 2
  • 19
  • 28