Lee Lee - 8 months ago 46
jQuery Question

I want to over-ride the functionality of jQuery function e.g. AJAX

I want to extend the functionality of AJAX so that on success and error I handle the request with my own extended functionality

Main function calling

var Type = "GET";
var URL = "http://localhost//getData.php";
var ContentType = "application/json; charset=utf-8";
var Data = "";

/////calling my ajax request////

myAjax.request( Type, URL, Data, ContentType, function(result){
//do something
});


Declaration of function

var myAjax = {
request : function( Type , URL , Data , ContentType ,callback){
$.ajax({
type: Type,
url: URL,
data: JSON.stringify(Data) ,
contentType: ContentType ,
success: function(data){},
error: function (request, status, error) {}
});
}
};


what I want to do is simply override AJAX function

Answer Source

if you just want to override the ajax so that you can handle its methods by extended functionality so you can done it by following way

(function($){
var $myAjax = $.ajax;

$.ajax = function(options){

     if (options.success) {
       //add your extended functionality here
     }
};

    // call original ajax function with modified arguments  
    $myAjax.apply($, arguments);
};
})(jQuery);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download