加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 请求标头字段预检响应中的Access-Control-Allow-He

发布时间:2020-12-17 06:58:54 所属栏目:安全 来源:网络整理
导读:当我试图保留以下代码来禁用ajax的缓存时,我收到此错误 angularApp.config(['appConfig','$httpProvider',function (appConfig,$httpProvider) {if (!$httpProvider.defaults.headers.get) { $httpProvider.defaults.headers.get = {};}//disable IE ajax re
当我试图保留以下代码来禁用ajax的缓存时,我收到此错误

angularApp.config(['appConfig','$httpProvider',function (appConfig,$httpProvider) {

if (!$httpProvider.defaults.headers.get) {
    $httpProvider.defaults.headers.get = {};
}

//disable IE ajax request caching
$httpProvider.defaults.headers.get['If-Modified-Since'] = 'Mon,26 Jul 1997 05:00:00 GMT';
$httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
$httpProvider.defaults.headers.get['Pragma'] = 'no-cache';

}]);

我在chrome中遇到如下错误:

请求标头字段预检响应中的Access-Control-Allow-Headers不允许使用Pragma.

但是当我删除以下代码时,它的工作正常.

$httpProvider.defaults.headers.get['If-Modified-Since'] = 'Mon,26 Jul 1997 05:00:00 GMT';
$httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache';
$httpProvider.defaults.headers.get['Pragma'] = 'no-cache';

谁能告诉我可能是什么问题?

解决方法

如果您可以在服务器端配置接受这些标头,那就没关系.
否则,您应该删除$httpProvider.defaulsts中设置的标头.
检查以下代码:

var data = {}
var httpCoonfig = {
    headers: {'Pragma': undefined,'Cache-Control': undefined,'X-Requested-With': undefined,'If-Modified-Since': undefined}
};
$http.post('https://www.google.com/',data,httpCoonfig).then(function(response){
// console.log(response)
},function(response){
     console.log(response)
});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读