首页 > 解决方案 > 编辑已经缩小的 JavaScript 片段

问题描述

我必须将下面的缩小片段编辑为:如果消息(字符串)由包含单词API的片段处理,则将整个消息更改为出错了。稍后再试。请让我知道我该怎么做。谢谢!

wc_myplugin.BaseGateway.prototype.submit_error = function(t) {
var e = this.get_error_message(t);
e.indexOf("</ul>") < 0 && (e = '<div class="' + function() {
    var t = "woocommerce-MyPlugin";
    return this.is_current_page("checkout") && (t += " woocommerce-MyPlugin-checkout"), t
}.bind(this)() + '"><ul class="woocommerce-error"><li>' + e + "</li></ul></div>");
t = o(document.body).triggerHandler("wc_myplugin_submit_error", [e, t, this]);
e = void 0 === t ? e : t, this.submit_message(e)

标签: javascriptajax

解决方案


var eMessage = e.contains('API') ? 'Something went wrong. Try again later' : e;在第三行添加。基本上,检查错误消息是否包含“API”(大写字母)。如果是,则替换错误消息,否则保持不变。

wc_myplugin.BaseGateway.prototype.submit_error = function(t) {
var e = this.get_error_message(t);
var eMessage = e.contains('API') ? 'Something went wrong. Try again later' : e;
e.indexOf("</ul>") < 0 && (e = '<div class="' + function() {
    var t = "woocommerce-MyPlugin";
    return this.is_current_page("checkout") && (t += " woocommerce-MyPlugin-checkout"), t
}.bind(this)() + '"><ul class="woocommerce-error"><li>' + eMessage + "</li></ul></div>");
t = o(document.body).triggerHandler("wc_myplugin_submit_error", [e, t, this]);
e = void 0 === t ? e : t, this.submit_message(e)

推荐阅读