Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 0.74 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Jquery Extend Existing Function
  2. $.adv_ajax()
  3.        
  4. $.adv_ajax({
  5.   custom_parameter: "abc", //my custom one
  6.   url: "test.html",
  7.   context: document.body,
  8.   success: function(){
  9.     $(this).addClass("done");
  10.   }
  11. });
  12.        
  13. $.adv_ajax = function(options) {
  14.     // Do stuff like change some options and then call the original
  15.     return $.ajax(options);
  16. }
  17.        
  18. (function($)
  19. {
  20.     // maintain a to the existing function
  21.     var oldAjax = $.ajax;
  22.     // ...before overwriting the jQuery extension point
  23.     $.fn.ajax = function()
  24.     {
  25.         // original behavior - use function.apply to preserve context
  26.         var ret = oldAjax.apply(this, arguments);
  27.  
  28.  
  29.         // preserve return value (probably the jQuery object...)
  30.         return ret;
  31.     };
  32. })(jQuery);