Backbone.js fetch callback

12,152

You're passing 2 separate arguments to fetch. Combine them into a single object with data, success, and error fields and it should work for you.

Share:
12,152
dzm
Author by

dzm

Updated on June 04, 2022

Comments

  • dzm
    dzm almost 2 years

    I'm using Backbone.js and using fetch with options, but it doesn't seem to get the error or success callbacks, however data is being returned.

    this.user.fetch({data: {username : this.username.val(), check : 'true'}}, {
        error: function(model, response) {
            console.log(response);
        },
        success: function(model, response)  {
            console.log(response);
        }
    });
    

    This is what I have setup, am I missing something? It never hits error or success, but it does do the ajax request and it's returning data.

    Thank you!

  • dzm
    dzm about 12 years
    Ahh, thank you! It's not returning the actual response though, it's going in the error function and it's returning some validation responses from within the model.
  • x1a4
    x1a4 about 12 years
    it seems like that would be a separate issue. glad you got this one taken care of!