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

3
  • where is setAddressLocationRows() set ? Commented Aug 3, 2018 at 11:14
  • setAddressLocationRows() is defined in "booking.js" file. Commented Aug 3, 2018 at 12:04
  • Check my answer. Commented Aug 3, 2018 at 12:21

1 Answer 1

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 and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.