本文介紹了Node js/Angular js - 注意:顯示臨時標題的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
這是我的 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. ');
});
這是我的 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'); });
我只是從 Angular 調用 POST localhost:3000/auth/signup 到 Node,但我得到 **CAUTION : 臨時標頭已顯示.**
在 chrome 控制臺中.
I'm just calling POST localhost:3000/auth/signup from Angular to Node, but i get **CAUTION : Provisional headers are shown.**
in chrome console.
鉻(小心):
Firefox(大約 30/60 秒沒有響應,然后出現 alert() :/):
Firefox (NO RESPONSE for about 30/60 seconds and then the alert() comes up :/ ):
這可能是什么?
如果我使用 GET 一切正常,只是使用 POST 我會遇到麻煩,這怎么可能?
IF i use GET everything is ok, is just with POST that i get troubles how is that possible?
推薦答案
我個人在 angular 中使用了這個reset"方法:
personaly I use this "reset" method in 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 = {};
}]);
這篇關于Node js/Angular js - 注意:顯示臨時標題的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!