压倒第三方JS [英] Overriding third party JS
问题描述
我们使用第三方控件套件,它具有我们想要自定义的JQuery全局 ajaxError
事件。我们不想更新这个JS文件,但想以某种方式覆盖它,以便JQuery不执行此事件。
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.
这可能吗?
编辑:第三方代码
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.');
}
}
我想从if条件开始使该行无效
I wan to nullify the line starting from the if condition
推荐答案
您可以覆盖整个方法,但不能只覆盖一个语句。
You could overwrite the whole method but not only a single statement.
编辑:
您正在使用的库是使用原型构建的。刚刚注意到您正在使用jQuery。因此,您可以使用jQuery.fn而不是LibName.prototype。覆盖它看起来类似于:
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
});
}
这篇关于压倒第三方JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!