【问题标题】:Loading javascript after AJAX loadAJAX 加载后加载 javascript
【发布时间】:2017-08-18 16:47:13
【问题描述】:

我有一个使用带有 AJAX 过滤器的灯箱产品的 woocommerce 网站。 要访问灯箱,当您将鼠标悬停在产品上时会出现一个快速查看按钮。

当我加载 AJAX 过滤器时,灯箱快速查看按钮不再可点击。 我需要在 AJAX 加载后将代码添加到按钮中。 下面是主题使用的功能。

85: function(t, e) {
            "use strict";
            Flatsome.behavior("quick-view", {
                attach: function(t) {
                    jQuery(".quick-view", t).each(function(t, e) {
                        jQuery(e).hasClass("quick-view-added") || (jQuery(e).click(function(t) {
                            if ("" != jQuery(this).attr("data-prod")) {
                                jQuery(this).parent().parent().addClass("processing");
                                var e = jQuery(this).attr("data-prod"),
                                    i = {
                                        action: "flatsome_quickview",
                                        product: e
                                    };
                                jQuery.post(flatsomeVars.ajaxurl, i, function(t) {
                                    jQuery(".processing").removeClass("processing"), jQuery.magnificPopup.open({
                                        removalDelay: 300,
                                        closeBtnInside: !0,
                                        autoFocusLast: !1,
                                        items: {
                                            src: '<div class="product-lightbox lightbox-content">' + t + "</div>",
                                            type: "inline"
                                        }
                                    }), setTimeout(function() {
                                        jQuery(".product-lightbox").imagesLoaded(function() {
                                            jQuery(".product-lightbox .slider").flickity({
                                                cellAlign: "left",
                                                wrapAround: !0,
                                                autoPlay: !1,
                                                prevNextButtons: !0,
                                                adaptiveHeight: !0,
                                                imagesLoaded: !0,
                                                dragThreshold: 15
                                            })
                                        })
                                    }, 300), jQuery(".product-lightbox form").hasClass("variations_form") && jQuery(".product-lightbox form.variations_form").wc_variation_form(), jQuery(".product-lightbox form.variations_form").on("show_variation", function(t, e) {
                                        e.image.src ? (jQuery(".product-lightbox .product-gallery-slider .slide.first img").attr("src", e.image.src).attr("srcset", ""), jQuery(".product-lightbox .product-gallery-slider .slide.first a").attr("href", e.image_link), jQuery(".product-lightbox .product-gallery-slider").flickity("select", 0)) : e.image_src && (jQuery(".product-lightbox .product-gallery-slider .slide.first img").attr("src", e.image_src).attr("srcset", ""), jQuery(".product-lightbox .product-gallery-slider .slide.first a").attr("href", e.image_link), jQuery(".product-lightbox .product-gallery-slider").flickity("select", 0))
                                    }), jQuery(".product-lightbox .quantity").addQty()
                                }), t.preventDefault()
                            }
                        }), jQuery(e).addClass("quick-view-added"))
                    })
                }
            })
        }

【问题讨论】:

    标签: javascript jquery ajax wordpress


    【解决方案1】:

    如果可以编辑主题,直接将代码写入成功回调中:

    jQuery.post(flatsomeVars.ajaxurl, i, function(t) {
      // Code you want to run
      // Other code. i.e. jQuery(".processing").removeClass ... etc.
    });
    

    或者定义函数并在你的 success() 回调中调用它。

    var myFunction = function() {
      // Code to run after success
    }
    jQuery.post(flatsomeVars.ajaxurl, i, function(t) {
       myFunction();
       // Other code
    });
    

    【讨论】:

    • 感谢我所需要的,问题是我真的不确定我必须运行什么代码,正在处理它!
    猜你喜欢
    • 2015-07-27
    • 2018-02-04
    • 1970-01-01
    • 2011-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-19
    相关资源
    最近更新 更多