节点JS / JS角 - 注意:临时标题所示 [英] Node js / Angular js - CAUTION: Provisional headers are shown

查看:201
本文介绍了节点JS / JS角 - 注意:临时标题所示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的角的js 件code:

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

我打电话POST本地主机:3000 /认证/从角到节点注册,但我得到 **注意:临时标题显示** 镀铬控制台。

铬(注意):

火狐(NO RESPONSE约30/60秒,然后报警()来了:/):

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?

推荐答案

本人来说我的角度用这种重置的方法:

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 = {};
}]);

这篇关于节点JS / JS角 - 注意:临时标题所示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆