Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overriding third party JS

We use a 3rd party control suite which has a JQuery global ajaxError event which we would like to customize. We don't want to update this JS file but want to somehow override it so that JQuery doesn't execute this event.

Is this possible?

EDIT: Third Party Code

    ajaxError: function (element, eventName, xhr, status) {
        var prevented = this.trigger(element, eventName,
            {
                XMLHttpRequest: xhr,
                textStatus: status
            });

        if (!prevented) {
            if (status == 'error' && xhr.status != '0')
                alert('Error! The requested URL returned ' + xhr.status + ' - ' + xhr.statusText);
            if (status == 'timeout')
                alert('Error! Server timeout.');
        }
    }

I wan to nullify the line starting from the if condition

like image 403
DotnetDude Avatar asked Nov 02 '10 20:11

DotnetDude


1 Answers

You could overwrite the whole method but not only a single statement.

EDIT: The library you're using is built using prototypes I guess. Just noticed you're using jQuery. Therefore you might use jQuery.fn instead of LibName.prototype. Overwriting it would look similar to:

jQuery.fn.ajaxError = function(element, eventName, xhr, status) {
  var prevented = this.trigger(element, eventName,
  {
    XMLHttpRequest: xhr,
    textStatus: status
  });
}
like image 197
pex Avatar answered Oct 21 '22 05:10

pex