Why are you making this mistake again?

Asked

Viewed 115 times

2

I’m using the plugin jQuery Datatable and started doing server-side activation

but when charging it informs an Alert:

Datatables Warning: table id=example - Invalid JSON Response. For more information about this error, Please see http://datatables.net/tn/1

Following I did the debug, and in the last step, where is to show the JSON with the data, appears: This request has no Sponse data available.

Why is this error still occurring? Because JSON’s Invalid Response, which is invalid????????

The page with the table html:

<script type="text/javascript" language="javascript" class="init">

$(document).ready(function() {
    $('#example').DataTable( {
        "processing": true,
        "serverSide": true,
        "ajax": "scripts/server_processing.php",

        "order": [[ 0, "asc" ]]
    } );
} );

</script>

And the server_processing.php:

<?php
$table = 'tbl_medic';
$primaryKey = 'id_Medic';

$columns = array(
    array( 'db' => 'nome', 'dt' => 0 ),
    array( 'db' => 'cidade',  'dt' => 1 ),
    array( 'db' => 'cep',   'dt' => 2 ),
    array( 'db' => 'crm',     'dt' => 3 ),
    array( 'db' => 'email', 'dt' => 4 ),
    array( 'db' => 'pastaDocumentos',     'dt' => 5 )
);

$sql_details = array(
    'user' => '***', //Usuário do banco de dados
    'pass' => '***', //Senha do banco de dados
    'db'   => '***', //Banco de dados
    'host' => 'localhost'
);

require_once( 'ssp.class.php' );
echo json_encode(
    SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
);

1 answer

0

Hello!!

Try to force the array to Object as follows:

$columns = (object) array(
    array( 'db' => 'nome', 'dt' => 0 ),
    array( 'db' => 'cidade',  'dt' => 1 ),
    array( 'db' => 'cep',   'dt' => 2 ),
    array( 'db' => 'crm',     'dt' => 3 ),
    array( 'db' => 'email', 'dt' => 4 ),
    array( 'db' => 'pastaDocumentos',     'dt' => 5 )
);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.