0

I have been assigned to update a classic asp website with a Prestashop template called Autotune Responsive Prestashop Theme. My client wants all the ajax bells and whistles they see online in Template Monster. Template Monster made static html files for my client from this template which includes all the custom Prestashop javascript libraries. So far I am unable to use these custom Prestashop jquery/ajax libaries as they were intended so I have to write my own code to paginate, add to cart, show item popup, etc. Everything works great except for appending html. For example, pagination. When I view a list of parts in grid view and I click to append nine more parts, the html gets appended OK but onclick events to the Add To Cart button and "eye" icon popup are dead for the new items that were appended. Mouse over events are OK. Same issue when I append html to the cart popup - I see the added cart items in the cart popup but the "x" (delete) won't work when clicked although the color changes when moused over. It's as if I need to update something after appending. I'm stumped. Here is the pagination code:

    $(function() {
        $('#infiniteScrollMore').click(function(){
            var numItems = parseInt($('#NumItems').text());
            var pageNbr = parseInt($('#PageNbr').text()) + 1;

            $('#PageNbr').text(pageNbr);

            $.get('AppendParts.asp?PageNbr=' + pageNbr + '&NumItems=' + numItems,function (data) {

                $('.product_list').append(data);

                numNextItems = parseInt(numItems) - (parseInt(pageNbr) * 9);

                if (parseInt(numNextItems) >= 9) numNextItems = 9;

                setTimeout(function(){$('#NumNextItems').text(' (' + numNextItems + ')')},2000);

                if ((parseInt(pageNbr) * 9) >= parseInt(numItems))
                {
                    $('#infiniteScrollMore').hide();
                    setTimeout(function(){$('#NewSearchButton').show();},2000);
                }
            });
        });
    });

I am just using .append to append html to the product_list ul. AppendParts.asp writes the html, which is...

    <li class="ajax_block_product">
        <div class="product-container" itemscope itemtype="https://schema.org/Product">
            <div class="left-block">
                <div class="product-image-container">
                    <div class="tmproductlistgallery rollover">
                        <div class="tmproductlistgallery-images opacity">
                            <a class="product_img_link cover-image" href="product.asp?PartNbr=<%=pageCache("PartNbr")%>&amp;StockNbr=<%=pageCache("StockNbr")%>&amp;ProductCode=<%=pageCache("ProductCode")%>&amp;MachineType=<%=pageCache("MachineType")%>&amp;Model=<%=pageCache("Model")%>&amp;Category=<%=pageCache("Category")%>&amp;SubCategory=<%=pageCache("SubCategory")%>" title="<%=pageCache("Description") & " " & pageCache("Make") & " " & pageCache("PartNbr") & " " & pageCache("Class")%>" itemprop="url">
                                <img class="img-responsive" src="http://<%=theImage%>" alt="" title="<%=pageCache("Description") & " " & pageCache("Make") & " " & pageCache("PartNbr") & " " & pageCache("Class")%>">
                            </a>
                            <a class="product_img_link rollover-hover" href="product.asp?PartNbr=<%=pageCache("PartNbr")%>&amp;StockNbr=<%=pageCache("StockNbr")%>&amp;ProductCode=<%=pageCache("ProductCode")%>&amp;MachineType=<%=pageCache("MachineType")%>&amp;Model=<%=pageCache("Model")&amp;Category=<%=pageCache("Category")%>&amp;SubCategory=<%=pageCache("SubCategory")" title="<%=pageCache("Description") & " " & pageCache("Make") & " " & pageCache("PartNbr") & " " & pageCache("Class")%>" itemprop="url">
                                <img class="img-responsive" src="http://<%=theImage%>" alt="" title="<%=pageCache("Description") & " " & pageCache("Make") & " " & pageCache("PartNbr") & " " & pageCache("Class")%>">
                            </a>
                        </div>
                    </div>
                    <div class="functional-buttons">
                        <div class="qv-wrap">
                            <a class="quick-view" data-id="<%=pageCache("ProductCode") & ":" & pageCache("StockNbr") & ":" & pageCache("PartNbr")%>" href="#" onclick="return false;" data-fancybox-type="ajax" data-type="ajax" data-href="#" title="Quick View"></a>
                        </div>
                        <div class="compare">
                            <a class="add_to_compare" href="product.asp?PartNbr=<%=pageCache("PartNbr")%>&amp;StockNbr=<%=pageCache("StockNbr")%>&amp;ProductCode=<%=pageCache("ProductCode")%>&amp;MachineType=<%=pageCache("MachineType")%>&amp;Model=<%=pageCache("Model")%>&amp;Category=<%=pageCache("Category")%>&amp;SubCategory=<%=pageCache("SubCategory")%>" data-id-product="<%=pageCache("ProductCode") & ":" & pageCache("StockNbr") & ":" & pageCache("PartNbr")%>" title="Detailed View"></a>
                        </div>
                    </div>

... abbreviated a bit. Here is the fancybox code:

$(function() {
        $('.quick-view').click(function(){
            var idStrArray = $(this).attr('data-id');
            var idStr = idStrArray.split(':');          
            var productCode = idStr[0];
            var stockNbr = idStr[1];
            var partNbr = idStr[2];

            $.fancybox({
                'closeClick': true,
                'hideOnContentClick': true,
                'padding': 0,
                'width': 1021,
                'autoDimensions': false,
                'height': 500,
                'type': 'iframe',
                'tpl': {wrap: '<div class="fancybox-wrap fancybox-quick-view" tabIndex="-1"><div class="fancybox-skin"><div class="fancybox-outer"><div class="fancybox-inner"></div></div></div></div>'},
                'href': 'product-popup.asp?PartNbr=' + partNbr + '&ProductCode=' + productCode + '&StockNbr=' + stockNbr,
                'beforeClose': function() {}
                }
            });
        });
    });     

What am I missing?

Slickhead
  • 1
  • 1

2 Answers2

0

You have to the event trigger like this -

$( "body" ).on( "click", "p", function() { alert( $( this ).text() ); });

Samik Chattopadhyay
  • 1,820
  • 6
  • 23
  • 34
0

Use jQuery .on() method. Read the doc

Empty Brain
  • 627
  • 8
  • 24