【问题标题】:Do something based on the alert message content根据警报消息内容做一些事情
【发布时间】:2016-03-15 14:59:46
【问题描述】:

我创建了一些自定义购物车警报,但目前我遇到了一些脚本运行一些应该刷新 Business Catalyst 中的购物车的 ajax 响应的问题。

我不确定它是什么,但给我时间看看发生了什么我需要根据警报消息做一些事情所以让我们说:

已将 1 件商品添加到您的购物车中,这将有助于 window.location.reload();

或者如果它只是说:你需要选择一个尺寸什么都不做

此刻我的警报是:

window.alert = function(message) {

$('.shop-main').addClass('blur');
$('.messageAlert').fadeIn().text(message).prepend('<img src="/images/ui-pieces/shopping-cart.png" width="40" height="40" alt="cart alert"/>');

setTimeout(function() { 

$('.messageAlert').fadeOut(); 
$('.shop-main').removeClass('blur');


  // window.location.reload();

}, 4000);
};

请让我知道我在这个阶段可以做到。

【问题讨论】:

标签: javascript jquery ajax business-catalyst


【解决方案1】:

您的关闭,您需要检查警报并在此基础上运行代码。

这是我在 BC 中所做的:

window.alert = function(text) {
    if (text.indexOf("Please choose relevant options before") > -1) {
        //CODE TO RUN IF ALERT MATCHES THE ABOVE TEXT
        $('#choose-option').foundation('reveal', 'open');
    } else if (text.indexOf("item(s) added to your cart") > -1) {
        //CODE TO RUN IF ALERT MATCHES THE ABOVE TEXT
        $('#store-modal').foundation('reveal', 'open');
    } else if (text.indexOf("Quantity entered is too large, please enter a smaller quantity.") > -1) {
        //CODE TO RUN IF ALERT MATCHES THE ABOVE TEXT
        $('#limited-quantity').foundation('reveal', 'open');
    } 
}; 

就我而言,我正在打开页面上的某些模式。您可以插入自己的 JS 代替模态代码。

【讨论】:

  • 感谢 Lynda,工作得很好,实际上我也可以进行其他一些交互式通话。您是否通常会收到原型错误消息,例如:prototype-core.ashx 拒绝设置不安全的标头“连接”基本上是为什么我必须使用自定义警报响应来刷新页面时将某些东西添加到购物车的原因,有趣的是只有在添加到购物车时才会发生这种情况,我通过清除所有冲突而一无所获!非常感谢您以任何方式提供的帮助,我将在另一个查询中发布。
  • @Skwashy - 我从未见过该消息,所以我不确定。您可以在Adobe BC Forums 上提问,看看是否有人可以更深入地了解这个问题。
  • 我已经做过了,但是只有一个人给了我一些建议,但效果不佳。我需要研究一下它是如何工作的,也许我会找到问题的根源。还是谢谢。
【解决方案2】:

使用此代码 - 开发 => 布局 => OnlineShop => small_product.html (将下面的代码粘贴到页面底部)

<span class="cartalert" style="display:none"></span>
<style>
.cartalert {
    position: fixed;
    bottom: 10%;
    right: 10%;
    padding: 15px 20px;
    text-align: center;
    background: #333;
    color: #fff !important;
    z-index:999999;
    border-radius: 5px;
    font-size: 16px;
}
</style>
<script>
$(function() {
     window.alert = function(msg) {
        msg = msg.replace('ERROR: ','');
        $('.cartalert').text(msg).fadeIn().delay(1000).fadeOut()
     } 
});
</script>

【讨论】:

    猜你喜欢
    • 2022-09-27
    • 1970-01-01
    • 2022-12-17
    • 2020-06-16
    • 2021-12-10
    • 2021-12-30
    • 1970-01-01
    • 2020-03-18
    • 2021-01-29
    相关资源
    最近更新 更多