防止多次显示弹出窗口.Ajax添加结果已在DOM中注册

Prevent showing popup more than once. Ajax-add-result is already registered in the DOM

本文关键字:结果 添加 DOM 注册 Ajax 窗口 显示      更新时间:2023-09-26

我很失望,因为我无法摆脱这个问题!我有一个产品视图和一个"添加到购物车"按钮。如果我点击按钮,表单将被提交(productAddToCartForm.submit(this)),并调用以下函数:

var myAjaxify = function(button) {
button.prop('disabled', true);
if (this.validator.validate()) {
  $(this.form).request({
    onComplete: function(response) {
      var responseData = JSON.parse(response.responseText);
      if (responseData.success === 'true') {
        Dialog.confirm(
          responseData.message,
          {
            className: 'openit',
            width: 385,
            height: 220,
            destroyOnClose: true,
            id: 'ajax-add-result',
            closable: true,
            zIndex: 100,
            title: 'Added to Your Cart',
            okLabel: 'Continue Shopping',
            cancelLabel: 'Proceed to Cart',
            onCancel: function() {
              window.location = '/checkout/cart';
            },
            buttonClass: 'action-btn'
          }
        );
        ...

但是需要几秒钟的时间,弹出窗口才会出现。如果我同时多次点击"添加到购物车"按钮,弹出窗口会出现不止一次。如果我没有足够快地关闭弹出窗口,我还会收到错误"ajax添加结果已经在DOM中注册"。我试图禁用按钮($(this).prop('disabled',true);),但我所有的解决方案都打破了剧本:(有人能帮我吗?

我们非常感谢您的每一次帮助。

最好,汉内斯。

取消设置按钮:)

$( "#yourbutton").unbind( "click" );

加载完所有内容后,您可以将事件绑定回。