ajaxhttp-status-code-200http-status-code-204

Normal to see Status 204 then Status 200?


I am looking at my ajax request in network tab in chrome and I noticed every ajax request I do happens twice.

First one is a 204 and then followed up with 200. My ajax call is only being hit once so I am not sure why there are 2.

Edit

So it seems to have to do with Cors, which I have just set to star (*) for testing.

I guess there is not to much I can do to not have it do 2 requests, but what really gets me is why it takes so long, I looking at google chrome network and on my page these 204 took anywhere from 110ms to 1.97 seconds.


Solution

  • That's a consequence of the CORS - Cross-origin resource sharing "protocol".

    When doing requests do other domains, the browser do a request before your request, asking for the server if it can proceed with that request.

    This request uses the method OPTIONS and should have no content, just response headers, that's why the response code is 204 (no content). After confirming that the request is allowed, the browser proceed with your request, that now will return 200 (or any other) status code.