$ http DELETE turns into AngularJS OPTIONS

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

Customer:

$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(); }); 
+6
source share
3 answers

The browser automatically sends a request for CORS SERIAL OPTIONS; this is the correct behavior, and you cannot avoid it. If the server allows the start, method, etc., the browser will follow the DELETE request.

+1
source

Isn’t it ok for pre-selling HTTP OPTIONS request for CORS? You may need to enable OPTIONS in your Access-Control-Allow-Methods list ...

0
source

I suggest you use $ resource instead of $ http. This will save you some template, therefore:

 var appServices = angular.module('appServices', [ 'ngResource' ]); appServices.factory('Account', ['$resource', function($resource) { return $resource('/accountUpdate/:accountMail', {accountMail: '@accountMail}); }]); 

after which you can enter your account and make a DELETE request as follows:

 Account.remove({accountMail: ' admin@admin.com '}); 

http://docs.angularjs.org/api/ngResource . $ resource

0
source

All Articles