
Untitled
By: a guest on
May 9th, 2012 | syntax:
None | size: 0.74 KB | hits: 19 | expires: Never
Jquery Extend Existing Function
$.adv_ajax()
$.adv_ajax({
custom_parameter: "abc", //my custom one
url: "test.html",
context: document.body,
success: function(){
$(this).addClass("done");
}
});
$.adv_ajax = function(options) {
// Do stuff like change some options and then call the original
return $.ajax(options);
}
(function($)
{
// maintain a to the existing function
var oldAjax = $.ajax;
// ...before overwriting the jQuery extension point
$.fn.ajax = function()
{
// original behavior - use function.apply to preserve context
var ret = oldAjax.apply(this, arguments);
// preserve return value (probably the jQuery object...)
return ret;
};
})(jQuery);