請求標頭字段預檢響應中的Access-Control-Allow-Headers不允許使用Pragma

[英]Request header field Pragma is not allowed by Access-Control-Allow-Headers in preflight response


I am getting this error when I was trying to keep the following code to disable cache for ajax

當我試圖保留以下代碼來禁用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';

}]);

I am getting error in chrome as follows:

我在chrome中遇到如下錯誤:

Request header field Pragma is not allowed by Access-Control-Allow-Headers in preflight response.

請求標頭字段預檢響應中的Access-Control-Allow-Headers不允許使用Pragma。

But when I remove the following code, its working fine.

但是當我刪除以下代碼時,它的工作正常。

$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';

can any one tell me what could be the problem?

誰能告訴我可能是什么問題?

1 个解决方案

#1


1  

If you can configure in server side to accept those headers, then it's fine. Else, you should remove those header which is set in $httpProvider.defaulsts. Check the code below:

如果您可以在服務器端配置接受這些標頭,那就沒關系。否則,您應該刪除$ 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)
});

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2016/03/25/7254d5e6033fd8c975982a2b8269fdd7.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com