How do I use the JSONP datatype with Ember Data?

前端 未结 2 811
迷失自我
迷失自我 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

    It's much easier to override the private ajaxOptions function instead of using jQuery. Ember's pipeline includes the removal of the jQuery dependency anyways. So do this instead:

    adapters/application.js:

    import DS from 'ember-data';
    
    export default DS.RESTAdapter.extend({
        ajaxOptions: function(url, type, options) {
            var hash = this._super(url, type, options);
            hash.dataType = "jsonp";
            return hash;
        }
    });
    

    It would be create if the Ember core team could expose a public method to officially support this (instead of hacking a private api).

    https://github.com/emberjs/data/blob/1.0.0-beta.15/packages/ember-data/lib/adapters/rest_adapter.js#L915

提交回复
热议问题