What causes invalid JSON error?

Asked

Viewed 2,276 times

2

I’ve done what was said in this post: json_encode - Invalid JSON and it hasn’t been resolved yet, so I’m asking.

I’m using the jquery datatables server side. I made the activation server side with the default repository in the datatables_demo table in the same database and everything worked. Now I just changed the table and generates that error:

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

I followed the instructions, debugged on the Chrome console, but no preview is available. Why is the Uncommon JSON error happening??? How can I check to fix the error?

PEOPLE HELP ME!!!

WHAT I NEED TO DO FOR YOU TO HELP ME???

Here the server response print

My page code with 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 )
);
  • What the JSON that is being returned?

  • It can be a lot. Better [Dit] the question and put the relevant part of the code.

  • So there’s no JSON returning, nothing @Marcelodeandrade

  • @bfavaretto, I will edit and later I call you, if possible I ask for your help

  • In the question you commented that you are using the datatbles. Please provide the code you are trying to execute and the table structure. Each item in the json should correspond to a column in the table. Therefore the importance of the structure.

  • I edited the question @Marcelodeandrade

  • I edited the question @bfavaretto

  • I edited the question @Djalmamanfrin

  • Tried to put this in php <?php header('Content-Type: application/json; charset=UTF-8'); ?

  • Yes, I tried. As stated in another POST here @Guilhermenascimento

  • Which post John?

  • https://answall.com/questions/36835/json-encode-json-inv%C3%A1lido @Guilhermenascimento

  • Are you sure there’s no room before the <?php?

  • Yes, absolutely certain

  • I debugged it by the datatable itself : debug.datatables.net/ujutog @Guilhermenascimento

  • But the problem is at the time of the request, so I think the problem is something else.

  • Can you understand my doubt? What I found strange is that in the same database, two different tables, when I set the pattern(datatables_demo), it works normal, and when I change the table(for tbl_medic), id and fields gives this damn error @Guilhermenascimento

  • Understand I understood yes John, the point is that it can be any problem, probably you turned off the errors of PHP and not managing to return anything detailed (ps: recommend errors on development environment and shut down errors on production).

  • 1

    @Johndoe500 comment on the code: echo json_encode(&#xA; SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )); and put a dd(); to see the return of the method. It should look like this: dd(SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns ));. Add the result to the question for analysis.

Show 14 more comments
No answers

Browser other questions tagged

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