Always got Method DELETE is not allowed by Access-Control-Allow-Methods in preflight response Always got Method DELETE is not allowed by Access-Control-Allow-Methods in preflight response angularjs angularjs

Always got Method DELETE is not allowed by Access-Control-Allow-Methods in preflight response


After some testing, I found the solution. I put the allow method on the header as below, then it works. I don't know why "*" doesn't work.

headers.add("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, DELETE");


Try using the CORS extension for chrome, it helped me once.

EDIT

This happens because angular adds X-Header keys in your request headers.

X-Headers generally define or set the operating parameters for the HTTP req/res

You can fix this by modifying the Content-Type of your requests to "text/plain" or "application/x-www-form-urlencoded" or "multipart/form-data".

You can do this by using an interceptor while in your app config.

EDIT

Add this to your server code -

header('Access-Control-Allow-Headers: X-Requested-With');

Try changing the content-type to text/plain

Hope this helps.