如何使用带有Ember Data的JSONP数据类型? [英] How do I use the JSONP datatype with Ember Data?
本文介绍了如何使用带有Ember Data的JSONP数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在进行ajax调用时将Ember Data设置为使用JSONP数据类型?我将使用Ember与Phonegap,并需要进行跨域请求。
How do I set up Ember Data to use the JSONP datatype when making its ajax calls? I am going to be using Ember with Phonegap and need to make cross-domain requests.
推荐答案
您需要创建自己的适配器它使用jsonp,你可以通过扩展一个现在就可以做到这一点,看看。
You need to create your own adapter which uses jsonp, you can do just that by extending a current one, have a look.
App.MyAdapter= DS.RESTAdapter.extend({})
然后你需要实现find方法等,使用jsonp,可以是这样的东西
Then you need to implement the find method among others, to use jsonp, could be something like this
App.MyAdapter= DS.RESTAdapter.extend({
find: function(store, type, id) {
var item;
$.ajax({
url: 'http://api.domain/someModel',
dataType: 'jsonp',
success: function(response){
item = App.someModel.create(order))
}
});
return item;
},
这没有测试,但它应该给你的想法,可以做到。 :)
This is not tested, but it should give you the idea of how i can be done. :)
这篇关于如何使用带有Ember Data的JSONP数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文