JavaScript Backbone Hash App #2 – the model – jsonp

//Answer Model
var AnswerModel = Backbone.Model.extend({

initialize: function(attributes, options) {
//passed in
this.Callback = attributes.callback;
this.Method = attributes.methodNeeded;
this.answerId = attributes.answerId;
},
url: function() {
return ‘http://’ + controllerUrl + ‘/cc/kfController/’ + this.Method + ‘/’ + this.answerId;
},

// override backbone synch to force a jsonp call
sync: function(method, model, options) {
var params = _.extend({
type: ‘GET’,
dataType: ‘jsonp’,
jsonpCallback: this.Callback,
url: model.url()+”?callback=?”,
processData: false
}, options);

// Make the request.
return $.ajax(params);
}
});

Leave a Reply

You must be logged in to post a comment.