Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$http DELETE turns into OPTIONS AngularJS

When I use put or delete, it turns into OPTIONS. I am using expressjs for my server framework.

Client:

$http({
    method: 'DELETE',
    url: HTTP_URL + '/update/account',
    params: { mail: mail }
});

Server:

app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Credentials", true);
res.header('Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE');
res.header("Access-Control-Allow-Headers",
    'Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept');
next();
});
like image 771
puppeteer701 Avatar asked Jan 08 '14 15:01

puppeteer701


1 Answers

The browser is automatically sending the CORS pre-flight OPTIONS request; this is correct behavior and you can't avoid it. If the server allows the origin, method, etc., then the browser will follow up with the DELETE request.

like image 62
Andy Dennie Avatar answered Oct 10 '22 08:10

Andy Dennie