Skip to content

Instantly share code, notes, and snippets.

@stubotnik
Created December 2, 2011 16:46
Show Gist options
  • Save stubotnik/1423920 to your computer and use it in GitHub Desktop.
Save stubotnik/1423920 to your computer and use it in GitHub Desktop.
pre-onComplete handler for all Ajax requests
xAjaxRequest = Class.create({
initialize: function (url, options) {
//if the request has a callback, wrap that in our own callback
if (typeof options.onComplete == "function") {
var f = options.onComplete;
options.onComplete =
function(r) {
if (this.preOnComplete(r)) {
f(r);
}
}.bind(this);
}
new Ajax.Request(url, options);
},
preOnComplete: function(r) {
console.log("I fire before all onComplete callbacks");
return true; //or return false to prevent callback from going ahead
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment