[英]Same origin policy when developing on local machine
Im using Ember and Ember-Model to develop a front end which is calling a Spring/Rest/MongoDB back end, which is all running on my local machine for development purposes, but I get the same origin policy error for my call. 我使用Ember和Ember-Model开发了一个前端,该前端调用了Spring / Rest / MongoDB后端,出于开发目的,该后端均在我的本地计算机上运行,但是我的调用却遇到了相同的源策略错误。
I want to know what the common work around for this is. 我想知道解决此问题的常见方法。
Here is my code: 这是我的代码:
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);
});
}
})
The same origin policy on localhost
is the same as on the rest of the web. localhost
上的原始策略与网络上的其他策略相同。 However, if you open your web app as a file (ie. the address starts with file:///
every other uri, even those of other files, will have a different origin. 但是,如果您以文件形式打开Web应用程序(即,地址以
file:///
开头,则每个其他uri,即使是其他文件的uri也将具有不同的来源。
To solve this, serve your app from a server running on your own machine, than look at it by going to http://localhost
. 要解决此问题,请从运行在您自己的计算机上的服务器上为您的应用程序提供服务,而不是通过访问
http://localhost
进行查看。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.