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???
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?– Marcelo de Andrade
It can be a lot. Better [Dit] the question and put the relevant part of the code.
– bfavaretto
So there’s no JSON returning, nothing @Marcelodeandrade
– JohnDoe500
@bfavaretto, I will edit and later I call you, if possible I ask for your help
– JohnDoe500
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 thejson
should correspond to a column in the table. Therefore the importance of the structure.– DNick
I edited the question @Marcelodeandrade
– JohnDoe500
I edited the question @bfavaretto
– JohnDoe500
I edited the question @Djalmamanfrin
– JohnDoe500
Tried to put this in php
<?php header('Content-Type: application/json; charset=UTF-8');
?– Guilherme Nascimento
Yes, I tried. As stated in another POST here @Guilhermenascimento
– JohnDoe500
Which post John?
– Guilherme Nascimento
https://answall.com/questions/36835/json-encode-json-inv%C3%A1lido @Guilhermenascimento
– JohnDoe500
Are you sure there’s no room before the
<?php
?– Guilherme Nascimento
Yes, absolutely certain
– JohnDoe500
I debugged it by the datatable itself : debug.datatables.net/ujutog @Guilhermenascimento
– JohnDoe500
But the problem is at the time of the request, so I think the problem is something else.
– Guilherme Nascimento
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
– JohnDoe500
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).
– Guilherme Nascimento
@Johndoe500 comment on the code:
echo json_encode(
 SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns ));
and put add();
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.– DNick