0

I am returning phtml file content on ajax call in Magento2 its working fine, In the phtml file I am loading jquery and mine custom js file booking, using below code. A query function running fine, but the custom is not loading because called js function returning not defined error -

Here is my code -

require([
    "jquery",
    "booking"   
    ], function(jQuery){
        jQuery(function ($) {
            $("#load_more").click(function(){
                var c = 1;
                var total_rows = 1;
                $.each($(".location_time"), function(){ 
                    if($(this).css("display") != 'none'){ ++total_rows; };
                    if($(this).css("display") == 'none' && c<=<?php echo $showRows;?>){
                        $(this).css("display","table-row");
                        ++c;
                    }   
                }); 
                if(total_rows == $('#total_rows').val() || c < <?php echo $showRows;?>){
                    $('#load_more').hide();
                }
            });


            bookingTable = $("#booking-table");

            setAddressLocationRows(bookingTable);
        });
    });

Error I am getting is -

Uncaught ReferenceError: setAddressLocationRows is not defined

Please let me know, what I am doing wrong.

Regards Atul

  • where is setAddressLocationRows() set ? – Avesh Naik Aug 3 '18 at 11:14
  • setAddressLocationRows() is defined in "booking.js" file. – Atul Aug 3 '18 at 12:04
  • Check my answer. – Avesh Naik Aug 3 '18 at 12:21
1

you forgot function(jQuery, booking){ and you need add change this booking.setAddressLocationRows(bookingTable);

require([
"jquery",
"booking"   
], function(jQuery, booking){
    jQuery(function ($) {
        $("#load_more").click(function(){
            var c = 1;
            var total_rows = 1;
            $.each($(".location_time"), function(){ 
                if($(this).css("display") != 'none'){ ++total_rows; };
                if($(this).css("display") == 'none' && c<=<?php echo $showRows;?>){
                    $(this).css("display","table-row");
                    ++c;
                }   
            }); 
            if(total_rows == $('#total_rows').val() || c < <?php echo $showRows;?>){
                $('#load_more').hide();
            }
        });


        bookingTable = $("#booking-table");

        booking.setAddressLocationRows(bookingTable);
    });
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.