How do I use the JSONP datatype with Ember Data?

前端 未结 2 796
迷失自我
迷失自我 2021-01-07 01:44

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.

2条回答
  •  时光说笑
    2021-01-07 02:07

    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({})
    

    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. :)

提交回复
热议问题