DataTables warning: table id=advanced-table - Invalid JSON ( XHR Instruction ) HELP ME

DataTables warning: table id=advanced-table - Invalid JSON ( XHR Instruction ) HELP ME

rafaswrafasw Posts: 78Questions: 7Answers: 0

CHECK NAVIGATOR NETWORK -> XHR -> PARAM

_ 1535899393400 columns[0][data] 0 columns[0][name] columns[0][orderable] true columns[0][search][regex] false columns[0][search][value] columns[0][searchable] true columns[1][data] 1 columns[1][name] columns[1][orderable] true columns[1][search][regex] false columns[1][search][value] columns[1][searchable] true columns[2][data] 2 columns[2][name] columns[2][orderable] true columns[2][search][regex] false columns[2][search][value] columns[2][searchable] true columns[3][data] 3 columns[3][name] columns[3][orderable] true columns[3][search][regex] false columns[3][search][value] columns[3][searchable] true columns[4][data] 4 columns[4][name] columns[4][orderable] true columns[4][search][regex] false columns[4][search][value] columns[4][searchable] true columns[5][data] 5 columns[5][name] columns[5][orderable] true columns[5][search][regex] false columns[5][search][value] columns[5][searchable] true columns[6][data] 6 columns[6][name] columns[6][orderable] true columns[6][search][regex] false columns[6][search][value] columns[6][searchable] true columns[7][data] 7 columns[7][name] columns[7][orderable] true columns[7][search][regex] false columns[7][search][value] columns[7][searchable] true columns[8][data] 8 columns[8][name] columns[8][orderable] true columns[8][search][regex] false columns[8][search][value] columns[8][searchable] true draw 1 length 50 order[0][column] 0 order[0][dir] asc search[regex] false search[value] start 0

CHECK NAVIGATOR NETWORK -> XHR -> RESPONSE
EMPTY

how to solve this problem?

Answers

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    CHECK NAVIGATOR NETWORK -> XHR -> RESPONSE EMPTY

    Looks like you enabled server side processing. You would need to debug your server script to understand why its not returning any data.

    Is you server script setup to support the parameters sent when using server side processing?

    What are you using for a server script?

    Kevin

  • rafaswrafasw Posts: 78Questions: 7Answers: 0

    `<?php

    header('Content-Type: application/json');

    /*
    * DataTables example server-side processing script.
    *
    * Please note that this script is intentionally extremely simply to show how
    * server-side processing can be implemented, and probably shouldn't be used as
    * the basis for a large complex system. It is suitable for simple use cases as
    * for learning.
    *
    * See http://datatables.net/usage/server-side for full details on the server-
    * side processing requirements of DataTables.
    *
    * @license MIT - http://datatables.net/license_mit
    */

    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    * Easy set variables
    */

    // DB table to use
    $table = 'usuarios';

    // Table's primary key
    $primaryKey = 'id';

    // Array of database columns which should be read and sent back to DataTables.
    // The db parameter represents the column name in the database, while the dt
    // parameter represents the DataTables column identifier. In this case simple
    // indexes

    $columns = array(
    array( 'db' => 'id', 'dt' => 0 ),
    array( 'db' => 'nome', 'dt' => 1 ),
    array( 'db' => 'email', 'dt' => 3 ),
    array( 'db' => 'cidade', 'dt' => 4 ),
    array( 'db' => 'estado', 'dt' => 5 ),
    array( 'db' => 'cep', 'dt' => 6 ),
    array( 'db' => 'data', 'dt' => 7 ),
    array( 'db' => 'hora', 'dt' => 8 )

    );

    // SQL server connection information
    $sql_details = array(
    'user' => 'root',
    'pass' => '',
    'db' => 'entt',
    'host' => 'localhost'
    );

    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
    * If you just want to use the basic configuration for DataTables with PHP
    * server-side, there is no need to edit below this line.
    */

    /*require( 'ssp.class.php' );

    echo json_encode(
    SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
    );*/

    require( 'ssp.class.php' );

    $d = SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns );

    var_dump( $d );

    echo json_encode( $d );`

  • rafaswrafasw Posts: 78Questions: 7Answers: 0

    I use wamp64

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @rafasw ,

    We're happy to take a look, but it would help, as per the forum rules, if you could link to a running test case showing the issue so we can offer some help. 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

  • rafaswrafasw Posts: 78Questions: 7Answers: 0

    data-tablec.php

    $(document).ready(function() {

      var advance = $('#advanced-table').DataTable( {
    
    
      dom: 'B<"clear">lfrtip',
    
      "deferRender": true,
      "serverSide": true,
      "processing": true, 
      "ajax": 'data/server_processing.php',   
          mark: true,
           columnDefs: [
            {
                targets: 1,
                className: 'noVis'
            },
            {
                "targets": [ 6 ],
                "visible": false
            },
            {
                "targets": [ 7 ],
                "visible": false
            }   
    
        ],
    
    buttons: {
        name: 'primary',
    
        buttons: [ 'copy', 'csv', 'excel', 'pdf', 'print', 'colvis'  ]
    },
    
    
    
    
          //"language": {
                //"url": "http://cdn.datatables.net/plug-ins/1.10.13/i18n/Portuguese-Brasil.json"
           // } 
    
    
    } );
    
    
    $('a.toggle-vis').on( 'click', function (e) {
        e.preventDefault();
    
        // Get the column API object
        var column = advance.column( $(this).attr('data-column') );
    
        // Toggle the visibility
        column.visible( ! column.visible() );
    } );  
    

    // Setup - add a text input to each footer cell
    $('#advanced-table tfoot th').each( function () {
    var title = $(this).text();
    $(this).html( '

    ' );
    } );
    // Apply the search
    advance.columns().every( function () {
    var that = this;

        $( 'input', this.footer() ).on( 'keyup change', function () {
            if ( that.search() !== this.value ) {
                that
                    .search( this.value )
                    .draw();
            }
        } );
    } );
    
    
    
    } );
    

    server_processing.php
    <?php
    $table = 'usuarios';
    $primaryKey = 'id';
    $columns = array(
    array( 'db' => 'nome', 'dt' => 0 ),
    array( 'db' => 'email', 'dt' => 1 ),
    array( 'db' => 'cidade', 'dt' => 2 )
    );

    $sql_details = array(
    'user' => 'root',
    'pass' => '',
    'db' => 'entt',
    'host' => 'localhost'
    );

    require( 'ssp.class.php' );

    echo json_encode(
    SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
    );

    DataTables warning: table id=advanced-table - Ajax error. For more information about this error, please see http://datatables.net/tn/7

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    Did you follow the troubleshooting steps provided in the link? http://datatables.net/tn/7

    What did you find?

    Kevin

  • rafaswrafasw Posts: 78Questions: 7Answers: 0

    now everything is working, but the following error as it is another error opened another topic

    https://datatables.net/forums/discussion/53141/error-requested-unknown-parameter#latest

    thanks man

This discussion has been closed.