在本地机器上开发时的同源策略
Same origin policy when developing on local machine
我正在使用 Ember 和 Ember-Model 开发一个调用 Spring/Rest/MongoDB 后端的前端,这在我的本地机器上都是 运行开发目的,但我的调用出现同源策略错误。
我想知道解决此问题的常见方法是什么。
这是我的代码:
App = Ember.Application.create();
App.Router.map(function(){
});
App.IndexRoute = Ember.Route.extend({
model: function(){
return App.User.find();
}
});
App.User = Ember.Model.extend({
lastName: Ember.attr()
});
App.User.adapter = Ember.Adapter.create({
findAll: function(klass, records) {
$.getJSONP("http://localhost:8080/users").then(function(data) {
records.load(klass, data.users);
});
}
})
localhost
上的同源策略与网络的其余部分相同。但是,如果您将 Web 应用程序作为文件打开(即地址以 file:///
开头,所有其他 uri,即使是其他文件的 uri,也将具有不同的来源。
要解决此问题,请在您自己的计算机上从服务器 运行 提供您的应用程序,然后转到 http://localhost
.
查看它
我正在使用 Ember 和 Ember-Model 开发一个调用 Spring/Rest/MongoDB 后端的前端,这在我的本地机器上都是 运行开发目的,但我的调用出现同源策略错误。
我想知道解决此问题的常见方法是什么。
这是我的代码:
App = Ember.Application.create();
App.Router.map(function(){
});
App.IndexRoute = Ember.Route.extend({
model: function(){
return App.User.find();
}
});
App.User = Ember.Model.extend({
lastName: Ember.attr()
});
App.User.adapter = Ember.Adapter.create({
findAll: function(klass, records) {
$.getJSONP("http://localhost:8080/users").then(function(data) {
records.load(klass, data.users);
});
}
})
localhost
上的同源策略与网络的其余部分相同。但是,如果您将 Web 应用程序作为文件打开(即地址以 file:///
开头,所有其他 uri,即使是其他文件的 uri,也将具有不同的来源。
要解决此问题,请在您自己的计算机上从服务器 运行 提供您的应用程序,然后转到 http://localhost
.