'success / error callback(s) not being invoked after 'fetch' (on Backbone.Collection)

I'm currently having a strange problem with (or around) Backbone. I have a Backbone collection object for which I put custom success and error callbacks.

A) ----> Working


    Fubars = Backbone.Collection.extend({ 
      
      url: "/listfubar",
      model: Fubar,
      fetchS: function() {
        fetch(  { success : sFn, 
                    error : eFn, 
                    statusCode : cFn 
        }); 
      },  
    })
    
    var fbars = new Fubars(); 
    fbars.fetchS();

B) ----> Breaking


    afterPoll = function() {   
        fbars.fetchS()
    }

This works fine when Fubars.fetchS is being invoked through a regular JavaScript file A). However, I'm having a problem when fetchS (and supplied callbacks) is itself invoked from an 'ajaxPoll' callback B) . fetchS is properly called, the callbacks all exist, and the network call is made through Backbone.sync > JQuery.ajax. But the success, error, or statusCode callbacks are never invoked (again, the network call definitely goes out, and returns successfully).

Has anyone run into this? I can only think that the success and error callbacks might somehow be disappearing, when afterPoll exits. But fubars is a global object, so that doesn't make any sense.

I've looked at similar posts (here), but not solving my problem. Any insights are greatly appreciated.



Solution 1:[1]

do this for fetch..

    
    (function fetch(){success:...,error:... }).call();
    or
    (function fetch(){return {success:...,error:...}
     }).call();
    
    

Solution 2:[2]

I suspect, problem may be due to the missing this.

Try to replace this statement:

    fetch(  { success : sFn, 
                error : eFn, 
                statusCode : cFn 
    }); 

with this statement:

    this.fetch(  { success : sFn, 
                error : eFn, 
                statusCode : cFn 
    });

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Karthik