$ http DELETE变成了OPTIONS AngularJS
当我使用put或delete的时候,它变成了OPTIONS。 我正在使用expressjs为我的服务器框架。
客户:
$http({ method: 'DELETE', url: HTTP_URL + '/update/account', params: { mail: mail } });
服务器:
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(); });
浏览器正在自动发送CORS飞行前OPTIONS请求; 这是正确的行为,你不能避免它。 如果服务器允许原点,方法等,则浏览器将跟进DELETE请求。
为CORS做预检HTTP OPTIONS请求是否正常? 您可能需要在您的Access-Control-Allow-Methods列表中允许OPTIONS …
我build议你使用$资源而不是$ http。 它会为你节省一些样板,所以:
var appServices = angular.module('appServices', [ 'ngResource' ]); appServices.factory('Account', ['$resource', function($resource) { return $resource('/accountUpdate/:accountMail', {accountMail: '@accountMail}); }]);
在此之后,您可以注入您的帐户服务,并进行DELETE请求,如下所示:
Account.remove({accountMail: 'admin@admin.com'});
- 使用Node.js res.send后,不能再调用Javascript对象上的方法
- AngularJS项目结构
- 使用MongoDB设置Angular / Ionic移动应用程序
- 在进行数据库调用时,如果控制器响应返回JSON对象,则无法在view.ejs中打印JSON对象值
- 用webpack将供应商库分成多个块
- 正确检索用户名和有用的值(网站标题,版权等)
- 如何使用ng-translate翻译dynamic内容(从使用api调用的数据库)
- 为Node.js服务器+ SPA javascript框架设置自动化BDDtesting环境的简单方法?
- IBM PushNotification:Not Found – 目标资源“PushDevice”不存在