javascript 节点 js / Angular js - 注意:显示临时标头
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21630534/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Node js / Angular js - CAUTION: Provisional headers are shown
提问by itsme
This is my Angular jspiece code:
这是我的Angular js代码:
$http({
method:'POST',
withCredential:true,
url:$scope.config.app_ws+'auth/signup',
data:{user:$scope.auth}
}).success(function(status, response){
console.log(response);
}).error(function(status, response){
alert(response+'Bummer :( , an error occured plese retry later. ');
});
This is my Node.jspiece backend:
这是我的Node.js后端:
var allow_cross_domain= function(req, res, next) {
res.header('X-Powered-By', 'hey.heyssssssss.org');
var oneof = false;
if(req.headers.origin) {
res.header('Access-Control-Allow-Origin', req.headers.origin);
oneof = true;
}
if(req.headers['access-control-request-method']) {
res.header('Access-Control-Allow-Methods', req.headers['access-control-request-method']);
oneof = true;
}
if(req.headers['access-control-request-headers']) {
res.header('Access-Control-Allow-Headers', req.headers['access-control-request-headers']);
oneof = true;
}
if(oneof) {
res.header('Access-Control-Max-Age', 60 * 60 * 24 * 365);
}
// intercept OPTIONS method
if (oneof && req.method == 'OPTIONS') {
res.send(200);
} else {
next();
}
}
app.use(allow_cross_domain);
app.post('/auth/signup', function (req, res) { res.send('wtff'); });
I'm just calling POST localhost:3000/auth/signup from Angular to Node, but i get **CAUTION : Provisional headers are shown.**
in chrome console.
我只是从 Angular 调用 POST localhost:3000/auth/signup 到 Node,但我进入**CAUTION : Provisional headers are shown.**
了 chrome 控制台。
Chrome (CAUTION):
铬(注意):
Firefox (NO RESPONSE for about 30/60 seconds and then the alert() comes up :/ ):
Firefox(大约 30/60 秒没有响应,然后 alert() 出现:/):
what this could be?
这可能是什么?
IF i use GET everything is ok, is just with POST that i get troubles how is that possible?
如果我使用 GET 一切正常,只是使用 POST 我会遇到麻烦,这怎么可能?
回答by Got The Fever Media
personaly I use this "reset" method in angular:
我个人在 angular 中使用这种“重置”方法:
app.config(['$httpProvider', function ($httpProvider) {
//Reset headers to avoid OPTIONS request (aka preflight)
$httpProvider.defaults.headers.common = {};
$httpProvider.defaults.headers.post = {};
$httpProvider.defaults.headers.put = {};
$httpProvider.defaults.headers.patch = {};
}]);
回答by qwertmax
this was fixed Mar 28, 2014 so it will be ok in next version of crome (v35)
这已于 2014 年 3 月 28 日修复,因此在下一版本的 crome (v35) 中没问题