admin管理员组文章数量:1355103
Here is my routes in (app/routes/customers.js):
export default Ember.Route.extend({
model: function() {
return $.getJSON("http://127.0.0.1:3000/odata/customers");
}
});
here is my router.js:
export default Router.map(function() {
this.route('customers', {path: '/'});
});
http://127.0.0.1:3000/odata/customers
is my api, but ember-cli use http://localhost:4200/
, when I open http://localhost:4200/
,
in the console, the error message is:
XMLHttpRequest cannot load http://127.0.0.1:3000/odata/customers. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
I find a article:
so I know what's wrong, but I don't kown how to fix it when use ember.js.
sorry for my poor English, hope thats clear...
Here is my routes in (app/routes/customers.js):
export default Ember.Route.extend({
model: function() {
return $.getJSON("http://127.0.0.1:3000/odata/customers");
}
});
here is my router.js:
export default Router.map(function() {
this.route('customers', {path: '/'});
});
http://127.0.0.1:3000/odata/customers
is my api, but ember-cli use http://localhost:4200/
, when I open http://localhost:4200/
,
in the console, the error message is:
XMLHttpRequest cannot load http://127.0.0.1:3000/odata/customers. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
I find a article: https://developer.mozilla/en-US/docs/Web/HTTP/Access_control_CORS
so I know what's wrong, but I don't kown how to fix it when use ember.js.
sorry for my poor English, hope thats clear...
Share Improve this question edited May 10, 2015 at 3:33 ChiangDi asked May 10, 2015 at 3:20 ChiangDiChiangDi 851 silver badge7 bronze badges1 Answer
Reset to default 8It's not Ember that is the problem. it's the server at port 3000. If your Ember app is running on a different port, it is basically cross domain and thus the server at port 3000 must be CORS enabled. Example of this is like this for node js and express: http://enable-cors/server_expressjs.html You need to figure out how to do this for your back end. But what it es down to is just basically adding the right headers into the response stream.
Some other example:
http://enable-cors/server_iis7.html
http://enable-cors/server_php.html
Note that if you do want to prevent the Ember server from sending requests to other origins, you can use Content Security Policies.
本文标签: javascriptAccessControlAllowOrigin error when using emberjs(with embercli)Stack Overflow
版权声明:本文标题:javascript - Access-Control-Allow-Origin error when using ember.js(with ember-cli) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743977012a2570919.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论