Created
February 25, 2016 15:22
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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