Issue with the script?

Issue with the script?

yskapellyskapell Posts: 47Questions: 14Answers: 3
edited January 2023 in Free community support

Hello all,

I have a strange issue.

I have the below code

    <script type="text/javascript">

        $(document).ready(function(){
            var table = $('#searchWords').DataTable({
            'processing': true,
            'serverSide': true,
             order: [[ 0, 'desc' ]],
            'serverMethod': 'post',
            'ajax': {
                'url':'voca_file.php'
            },
            'columns': [
                {data: 'id' },
                { data: 'ideogram' },
                { data: 'pinyin' },
                { data: 'type' },
                { data: 'meaning' }
            ]
            });

        });
    </script>

Some times it does not call the php file and as result I get this

If I click somewhere else and then back on the link to open the page I get the results.

Why the script does not call the php file?

What am I missing?

Also I load those libraries.

    <link href='../students/dataTables/datatables.min.css' rel='stylesheet' type='text/css'>
    <script src="../students/dataTables/datatables.min.js"></script>
    <script type="text/javascript" src="../students/dataTables/DataTables-1.13.1/js/jquery.dataTables.min.js"></script>

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951

    Generally if a page isn't behaving as expected you are getting Javascript errors. Look at the browser's console for errors. Let us know what you find.

    Its hard to say what the problem might be without seeing the issue. If you still need help then post a link to your page or a test case replicating the issue so we can help debug.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • yskapellyskapell Posts: 47Questions: 14Answers: 3
    edited January 2023

    There are no console errors.

    in this link https://kaiqiaozhi.space/out.ogv I have record the issue

    I have add the script here http://live.datatables.net/guwafemu/339/edit

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951

    Unfortunatey its impossible to debug videos but I do see a couple errors at the beginning:

    Not sure where they came from or if they are causing the issue. We will need to see a page with the problem to help debug.

    Maybe start by adding a breakpoint it the first statement in your Javascript code and step through the code. You might find where the issue is.

    Kevin

  • yskapellyskapell Posts: 47Questions: 14Answers: 3

    Those error are not related to the code. I add the code I use here http://live.datatables.net/guwafemu/339/edit

    I know that you cannot debug video, just wanted to show you the case...

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951
    edited January 2023

    Your test case is getting this error:

    DataTables warning: table id=searchWords - Incorrect column count. For more information about this error, please see http://datatables.net/tn/18

    I will assume you aren't getting this error in your site and we can ignore it. However if you are then you need to make sure your header columns match the tbody columns.

    I'm not seeing the issue with the test case. Please provide the steps to show the problem.

    In your screenshot and video it doesn't seem like the code is getting to the point of initializing Datatables. Maybe try putting a breakpoint where Datatables is initialized. When the error occurs does it get to the breakpoint?

    Kevin

  • yskapellyskapell Posts: 47Questions: 14Answers: 3

    In the video I show the issue.

    Also I show you that I get no error when I clear everything.

    I get no error like " http://datatables.net/tn/18 " or any other error

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951

    Yes, I see that. Again its impossible to debug your issue without actually seeing it. Have you tried using the browser breakpoints like I suggested?

    Kevin

  • yskapellyskapell Posts: 47Questions: 14Answers: 3

    The script is on a php file, so I cannot add breakpoints.

    If you want I can give you the link with the issue

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951

    Thanks for the PM with the link. I'm not familiar with React so not sure how to place a breakpoint in show_student_vocabulary.php. Try adding a console.log statement to this code in show_student_vocabulary.php to see if $(document).ready() is being called. Like this:

        <script type="text/javascript">
    
            $(document).ready(function(){
                console.log('before');
                var table = $('#searchWords').DataTable({
                'processing': true,
                'serverSide': true,
                 order: [[ 0, 'desc' ]],
                'serverMethod': 'post',
                'ajax': {
                    'url':'voca_file.php'
                },
                'columns': [
                    { data: 'id' },
                    { data: 'ideogram' },
                    { data: 'pinyin' },
                    { data: 'type' },
                    { data: 'meaning' }
                ]
                });
                console.log('after');
            });
        </script>
    

    Kevin

  • kthorngrenkthorngren Posts: 21,336Questions: 26Answers: 4,951
    Answer ✓

    The other thing I would do is in student_details.php comment out this code:

        <script>
            $(function () {
                $('#myTab li:first-child a').tab('show')
            })
        </script>
    

    Its causing this error before opening the Λεξικό link. Could be causing the $(document).ready() function to not run.

    Kevin

Sign In or Register to comment.