Skip to content

Instantly share code, notes, and snippets.

@krambuhl
Created March 2, 2014 05:46
Show Gist options
  • Save krambuhl/9302506 to your computer and use it in GitHub Desktop.
Save krambuhl/9302506 to your computer and use it in GitHub Desktop.
Backbone Jsonp Collection. only supports simple get commands.
Backbone.JsonpCollection = Backbone.Collection.extend({
sync: function(method, model, options) {
var params = _.extend({
type: 'GET',
url: this.url,
dataType: "jsonp",
processData: false
}, options);
return $.ajax(params);
},
parse: function(response) {
if (this.type && response[this.type]) {
return response[this.type];
} else {
return response;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment