0

I'm doing a simple fetch with a model directly in backbone.

This works perfectly.

model.fetch({
        success: function () {
            alert("success");                
        },
        error: function () {
            alert("error with data!!");
        },
        change: function () {
            alert("change");
        }
    });

However I want to sent a parameter with the request, but when I do this, it stops working? No errors reported?

model.fetch({ data: { userId: userId} },{
        success: function () {
            alert("success");                
        },
        error: function () {
            alert("error with data!!");
        },
        change: function () {
            alert("change");
        }
    });

Can anyone help? The request looks like to goes and comes back from the server perfectly?

Chris Barry
  • 4,564
  • 7
  • 54
  • 89

1 Answers1

4

This seems to have been answered before already.

Backbone.js fetch with parameters

Also I think you do not have to wrap your callback functions in a separate object, but they can be stored in the same one as the data variable.

Like this:

...fetch({data: $.param({...}), success: ..., error: ...});
Community
  • 1
  • 1
jakee
  • 18,486
  • 3
  • 37
  • 42
  • Doh, so stupid of me. Obviously by doing it the way I was doing it, I was moving the location of the callbacks, so they couldn't be found. – Chris Barry Jun 11 '12 at 17:03
  • I'm also not sure if there even exists a change callback for fetch. In the documentation they refer to a change event you can bind actions to. – jakee Jun 11 '12 at 17:06
  • "change" is automatically triggered on fetch if the server's state is different from the model's state. – Brendan Delumpa Jun 11 '12 at 21:18
  • I actually thought the same thing, I just chucked change in there in case it was something that was happening. So stupid of me! – Chris Barry Jun 12 '12 at 09:47