How to handle CORS issue, API called twice?

#1

Hi,

I have integrated change password API with header (‘Content-Type’, ‘application/json’). API called twice,
1st - Request Method: OPTIONS
2nd - Request Method: GET

The password gets changed with the 1st request but I got the response of the 2nd request. That was the wrong response which I got. I want to handle the 1st request’s response which is the correct response.

Please help to handle that request.

Thank You.

#2

Hi @ashokInceptive :wave:

The first OPTIONS request is a preflight request, automatically sent by the browser in order to check for CORS support.

The backend shouldn’t actually do any action in response to this preflight request, just allow the origin, headers or authentication. The action should be performed server-side on the actual GET request. If it’s not happening this way, then the server CORS implementation is not correct.

More info in the CORS Errors page in the Ionic docs.

Best,
Rodrigo

#3

Hi, @FdezRomero

Thanks for your help. I used observable to call API. It gets called once and gives me an appropriate response.