假设我有一个给定的余烬应用程序
App = Ember.Application.create()
路由器
App.Router.map(function() {
this.resource("posts", function() {
this.resource("post", {
path: "/:post_id"
})
});
});
Run Code Online (Sandbox Code Playgroud)
每当应用程序进入给定的/:post_id时,如何执行函数?
我正在创建一个简单的JSON API,它只使用jsonp使用node-js返回一个对象.这是服务器端的代码:
app.get('/vit',function (req,res,next) {
res.type('application/json');
res.jsonp(items); //items is the object
});
Run Code Online (Sandbox Code Playgroud)
在部署到nodejitsu,并转到url/vit时,我得到了对象项.这意味着它在服务器端工作.
我有另一个域,我想在哪里使用jsonp获取此对象Heres客户端代码:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$.getJSON('http://trial.jit.su/vit',function (data) {
console.log(data) ;
});
</script>
Run Code Online (Sandbox Code Playgroud)
但是我在控制台上收到以下错误:
XMLHttpRequest cannot load http://trial.jit.su/vit. Origin http://jquer.in is not allowed by Access-Control-Allow-Origin.
Run Code Online (Sandbox Code Playgroud)
好像我还不懂Jsonp.