Skip to content

Instantly share code, notes, and snippets.

@hardboiled
Created February 25, 2016 15:22
Show Gist options
  • Save hardboiled/ed6ab7ee4e34167e28cc to your computer and use it in GitHub Desktop.
Save hardboiled/ed6ab7ee4e34167e28cc to your computer and use it in GitHub Desktop.
This is a JS snippet similar to one that I wrote for an optimizely experiment that needed up update button text everytime a new set of products on our site was fetched. The markup would render and then my callback would replace the text for the users in the experiment.
yourCb = function(){
console.log('hello world');
};
jQuery(function(){
var w$ = window.$;
var oldAjax = w$.ajax;
w$.ajax = function(settings){
var url = (typeof settings === "string") && settings;
var success = null;
if (url) {
settings = {url:url};
} else {
success = settings.success;
}
settings.success = function(){
success && success.apply(null, arguments);
yourCb();
};
oldAjax(settings);
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment