Search code examples
backbone.jsjsonp

how to handle the jsonp callback function using backbone


I am new to Backbone, and I am confused about its jsonp calls.

I know I can do something like this:

var foo = Backbone.Model.extand({
    url : "/testing"          
});
var fooInstance = new foo();
fooInstance.fetch({dataType: "jsonp"});

what about the callback function, is it handle by jQuery? if it is..does Backbone has something like "success : function(data){console.log(data)}" ?


Solution

  • Just write the callback function inside the fetch method.

    fooInstance.fetch({
    dataType: "jsonp",
    success: function() {
        //Code  ...
       },
    error:function() {
        //Code  ...
     }
    });