当我尝试保留以下代码以禁用 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 不允许请求 header 字段 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';
谁能告诉我可能是什么问题?
最佳答案
如果您可以在服务器端进行配置以接受这些 header ,那就没问题了。
否则,您应该删除在 $httpProvider.defaulsts 中设置的那些 header 。
检查下面的代码:
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)
});
关于angularjs - 预检响应中的 Access-Control-Allow-Headers 不允许请求 header 字段 Pragma,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36218950/