Chi*_*gDi 6 javascript http ember.js
这是我在(app/routes/customers.js)的路线:
export default Ember.Route.extend({
model: function() {
return $.getJSON("http://127.0.0.1:3000/odata/customers");
}
});
Run Code Online (Sandbox Code Playgroud)
这是我的router.js:
export default Router.map(function() {
this.route('customers', {path: '/'});
});
Run Code Online (Sandbox Code Playgroud)
http://127.0.0.1:3000/odata/customers是我的api,http://localhost:4200/但当我打开时http://localhost:4200/,使用ember-cli ,
在控制台中,错误消息是:
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.
我找到一篇文章:https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
所以我知道什么是错的,但我不知道在使用ember.js时如何修复它.
抱歉我的英语不好,希望这清楚......
这不是Ember问题.它是端口3000上的服务器.如果您的Ember应用程序在不同的端口上运行,它基本上是跨域的,因此端口3000上的服务器必须启用CORS.对于节点js和express,这样的示例是这样的:http://enable-cors.org/server_expressjs.html 您需要弄清楚如何为后端执行此操作.但它归结为基本上只是将正确的标题添加到响应流中.
其他一些例子:
http://enable-cors.org/server_iis7.html
http://enable-cors.org/server_php.html