Third-Party JS Override

We are using a third-party management pack that has the ajaxError jQuery global event that we would like to configure. We do not want to update this JS file, but we want to somehow redefine it so that JQuery does not execute this event.

Is it 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 want to collapse a line starting with an if condition

+6
javascript jquery
source share
3 answers

You can overwrite the entire method, but not just one statement.

EDIT : The library you are using is built using the prototypes I assume. You are just using jQuery. Therefore, you can use jQuery.fn instead of LibName.prototype. The rewrite will look like this:

 jQuery.fn.ajaxError = function(element, eventName, xhr, status) { var prevented = this.trigger(element, eventName, { XMLHttpRequest: xhr, textStatus: status }); } 
+1
source share

You can override any property as follows:

  var thirdParty = { override: function() { alert('this function should have been overridden'); } }; var thirdPartyOriginal = thirdParty.override; thirdParty.override = function() { alert('this function has been overridden'); }; thirdParty.override(); thirdParty.override = thirdPartyOriginal; 

The example shows saving the original, and then after executing the new code. I will return it back to its original state.

0
source share
 public class MyClass: MC { protected override void OnError(..) { //handle error, send error to where ever } } 
-one
source share

All Articles