我怎样才能让我的ngResource接受自定义页眉? [英] How can I get my ngResource to accept custom headers?

查看:105
本文介绍了我怎样才能让我的ngResource接受自定义页眉?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的code在CoffeeScript的:

My code in coffeescript :

  resource = $resource GlobalService.apiRoot + "stuffs", {},
    get:
      method: "GET"
      headers:
        "Accept": "application/stuffs;version=3"
        "Authorization": 'Token token="' + $.cookie('token') + '"'

我的code在JavaScript:

My code in javascript :

var resource;

resource = $resource(GlobalService.apiRoot + "stuffs", {}, {
  get: {
    method: "GET",
    headers: {
      "Accept": "application/stuffs;version=3",
      "Authorization": 'Token token="' + $.cookie('token') + '"'
    }
  }
});

后来,当我做..

Then when I do..

resource.get ->

它不会发出那些指定头,并且有效地失败CORS授权。

It doesn't send out those specified headers, and effectually fails the CORS authorization.

任何建议?

推荐答案

看起来像头设置只在角最新的不稳定的版本中提供。如果你使用这个,一定要既angular.js和angular.resource.js升级到1.1.2(当前不稳定的版本)。

Looks like that headers setting is only available in the latest "unstable" release of Angular. If you use this, be sure to upgrade both angular.js and angular.resource.js to 1.1.2 (current unstable release).

  • http://code.angularjs.org/1.1.2/angular.js
  • http://code.angularjs.org/1.1.2/angular-resource.js

这篇关于我怎样才能让我的ngResource接受自定义页眉?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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