Skip to content

How can I Reload custom Popup when ajax Success In Magento2?

strong textI Have Custom Popup with Special Products when Someone Click On Add to cart On Category Page Product than Popup Open and They Show Special Products So The Problem is When i add To Cart Product From Popup than It Not add in Popup Real Time What Can I Do ? Below Is My code

enter image description here

$('.popupaddtocart').on('click', function (event) {
            event.preventDefault();

            var baseUrl = urlBuilder.build('');
            var productId = $(this).find('#popupproductid').text();
            var requestURL = baseUrl + 'popupwithslider/popup/productaddtocart';
            var info = "";
            $.ajax({
                url: requestURL,
                method: 'POST',
                data: {
                    productId: productId,
                },
                showLoader: true,
                success: function (response) {
                    var sections = ['cart'];
                    customerData.reload(sections, true);

                    if (response.success) {
                        if (response.hasOwnProperty('message')) {
                            $(".updatemessage")
                                .css("visibility", "visible")
                                .addClass("message-success success message")
                                .html("Item Inserted Successfully");
                        } else if (response.hasOwnProperty('url')) {
                            window.location.href = response.url;
                            return;
                        }
                    } else {
                        console.error('Error adding product to cart.');
                    }
                error: function () {
                    console.error('Error adding product to cart.');
                }
            });
        });