Skip to content

Instantly share code, notes, and snippets.

@JesseObrien
Forked from tgriesser/gist:5247103
Created March 26, 2013 20:57
Show Gist options
  • Save JesseObrien/5249176 to your computer and use it in GitHub Desktop.
Save JesseObrien/5249176 to your computer and use it in GitHub Desktop.
// Overriding sync
var Sync = Backbone.sync;
Backbone.sync = function (method, model, options) {
var success = options.success;
var error = options.error;
// Your custom code goes here, you should be able to access
// the xhr via options.xhr, or in the second argument from the ajax call.
options.success = function (resp, status, xhr) {
success.apply(this, arguments);
alert("Success with model " + JSON.stringify(model));
};
options.error = function (xhr, status, error) {
error.apply(this, arguments);
alert("Error with model " + JSON.stringify(model));
};
return Sync.call(this, method, model, options);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment