ajax.reload is not a function

ajax.reload is not a function

manuelgarciaphmanuelgarciaph Posts: 3Questions: 1Answers: 0
var MBGDATATABLE = $('#MBG_ALS_USERS').DataTable({ ... });

MBGDATATABLE.ajax.reload();

So i had this code and it has been working perfectly fine... Then, I realized that whenever I update the table while on a certain page except page number 1, the table redirects on the page number 1.

To fix this, I revised the reload as per the documentation:

MBGDATATABLE.ajax.reload(null, false);

All of a sudden, it doesn't update anymore and it displays "Uncaught TypeError: MBGDATATABLE.ajax.reload is not a function". I tried to undo the change and returned to the original code. Same error. I didn't change anything except this line on all of my pages that have ajax.reload. Any idea?

Answers

  • colincolin Posts: 15,118Questions: 1Answers: 2,583

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • manuelgarciaphmanuelgarciaph Posts: 3Questions: 1Answers: 0

    Thanks Colin. I added the HTML and JS code here: http://live.datatables.net/bunalapo/1/edit?html,js

    I used server-side and JSON using the following:

    <?php
        include("../sessions.php");
        include("../functions.php");
        $sql_details = array(
            'user' => DB_USERNAME,
            'pass' => DB_PASSWORD,
            'db'   => DB_NAME,
            'host' => DB_SERVER
        );
    
        $table = 'als_users';
        $primaryKey = 'id';
    
        $columns = array(
            array( 'db' => 'id', 'dt' => 0),
            array( 'db' => 'first_name', 'dt' => 1, 
                   'formatter'=> function($d, $row){ return htmlspecialchars($d); }),
            array( 'db' => 'last_name', 'dt' => 2,
                   'formatter'=> function($d, $row){ return htmlspecialchars($d); }), 
            array( 'db' => 'phone', 'dt' => 3,
                   'formatter'=> function($d, $row){ return htmlspecialchars($d); }), 
            array( 'db' => 'status', 'dt' => 4,
                   'formatter'=> function($d, $row){ return htmlspecialchars($d); }),
            array( 'db' => 'volume', 'dt' => 5,
                   'formatter'=> function($d, $row){ return htmlspecialchars($d); }),
            array( 'db' => 'email', 'dt' => 6,
                   'formatter'=> function($d, $row){ return htmlspecialchars($d); }),
            array( 'db' => 'date_registered', 'dt' => 7,
                   'formatter'=> function($d, $row){ return htmlspecialchars($d); }),
            array( 'db' => 'role', 'dt' => 8,
                   'formatter'=> function($d, $row){ return htmlspecialchars($d); }),
            array( 'db' => 'image', 'dt' => 9),
        );
    
        
    
        require( 'datatables-ssp.php' );
        echo json_encode(
            SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
        );
    
    ?>
    
  • manuelgarciaphmanuelgarciaph Posts: 3Questions: 1Answers: 0

    I added the HTML and JS code in here: http://live.datatables.net/bunalapo/1/edit?html,js

    I used server-side and JSON:

    <?php
        include("../sessions.php");
        include("../functions.php");
        $sql_details = array(
            'user' => DB_USERNAME,
            'pass' => DB_PASSWORD,
            'db'   => DB_NAME,
            'host' => DB_SERVER
        );
    
        $table = 'als_users';
        $primaryKey = 'id';
    
        $columns = array(
            array( 'db' => 'id', 'dt' => 0),
            array( 'db' => 'first_name', 'dt' => 1, 
                   'formatter'=> function($d, $row){ return htmlspecialchars($d); }),
            array( 'db' => 'last_name', 'dt' => 2,
                   'formatter'=> function($d, $row){ return htmlspecialchars($d); }), 
            array( 'db' => 'phone', 'dt' => 3,
                   'formatter'=> function($d, $row){ return htmlspecialchars($d); }), 
            array( 'db' => 'status', 'dt' => 4,
                   'formatter'=> function($d, $row){ return htmlspecialchars($d); }),
            array( 'db' => 'volume', 'dt' => 5,
                   'formatter'=> function($d, $row){ return htmlspecialchars($d); }),
            array( 'db' => 'email', 'dt' => 6,
                   'formatter'=> function($d, $row){ return htmlspecialchars($d); }),
            array( 'db' => 'date_registered', 'dt' => 7,
                   'formatter'=> function($d, $row){ return htmlspecialchars($d); }),
            array( 'db' => 'role', 'dt' => 8,
                   'formatter'=> function($d, $row){ return htmlspecialchars($d); }),
            array( 'db' => 'image', 'dt' => 9),
        );
    
        
    
        require( 'datatables-ssp.php' );
        echo json_encode(
            SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
        );
    
    ?>
    
  • kthorngrenkthorngren Posts: 20,150Questions: 26Answers: 4,736

    The test case isn't running and doesn't appear to have the MBGDATATABLE.ajax.reload(null, false); statement. The purpose of the test case is so we can run the page and debug the running code.

    If you are unable to provide a link to your page or a running test case then I suggest you use the browser's debugger and place a breakpoint at the MBGDATATABLE.ajax.reload(null, false); statement. This is the place to start to see what is happening.

    Make sure MBGDATATABLE is assigned to the datatable API using var MBGDATATABLE = $('#MBG_ALS_USERS').DataTable() not var MBGDATATABLE = $('#MBG_ALS_USERS').dataTable() with a lower case d fir datatable. Make sure you aren't reassigningMBGDATATABLEto something else before usingMBGDATATABLE.ajax.reload(null, false);`.

    Kevin

This discussion has been closed.