Skip to content

Instantly share code, notes, and snippets.

@tgriesser
Created March 26, 2013 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tgriesser/5247103 to your computer and use it in GitHub Desktop.
Save tgriesser/5247103 to your computer and use it in GitHub Desktop.
Overriding sync globally.
// 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