【发布时间】:2013-06-17 09:18:09
【问题描述】:
当我从 ember-rails 移动到外部 ember 应用程序时,我正在使用具有不同 URL 的 ember 数据,因此 API url 是 http://localhost:5000 而 ember 应用程序是 http://localhost:9000。
现在的问题是我需要包含x-appid 和x-app-secret,但是每当为其中任何一个添加xhr.setRequestHeader() 时,GET 请求就会变为OPTIONS 请求。
当我在同一个域上使用 ember-rails 时,这段代码运行良好,这是问题还是缺少其他东西?
ajax: function(url, type, hash) {
if (this.headers !== undefined) {
var headers = this.headers;
if (hash) {
hash.beforeSend = function (xhr) {
// Works fine
xhr.setRequestHeader('Accept', 'application/vnd.vendor+json;version=1');
// Changes Request from GET to OPTIONS
xhr.setRequestHeader('x-vendor-appid', '12412412');
xhr.setRequestHeader('x-vendor-secret', 'aslkdfjaskldfjasd');
};
}
}
return this._super(url, type, hash);
}
【问题讨论】:
标签: jquery ember.js ember-data