Invalid JSON Response from jQuery Server Side
Invalid JSON Response from jQuery Server Side
I copied the server-side example files from github.com/DataTables/DataTables/tree/master/examples/server_side:
the HTML file I used was simple.html and the scripts: server_processing.php and ssp.class.php, and I modified the database configuration to my specifications. I inserted mysql.sql (copied from the same location) in my DB also without modification.
They are in the same DB. If I use the default configuration(same $sql_details and $collumns) it works fine. Howerever if I change the $columns(same $sql_details, but diferent $collumns), it gives me the creeping error message:
DataTables warning: table id=example - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1
I followed the advice in http://datatables.net/tn/1 but the network response didn't display the faulty json format but the message: This request has no response data available.
https://i.stack.imgur.com/fk3vo.png
I used the Data Tables debugger which returned the reference: debug.datatables.net/ujutog.
I am greatly thankful if somebody could point out an error, cause there is no response available.
I asked question in Stackoverflow, but there was "no preview answer available".
https://stackoverflow.com/questions/44849202/invalid-json-response-from-datatable-server-side
https://pt.stackoverflow.com/questions/217557/o-que-ocasiona-o-erro-de-json-inv%C3%A1lido
https://pt.stackoverflow.com/questions/216368/resposta-inv%C3%A1lida-json
This question has an accepted answers - jump to answer
Answers
That is faulty JSON . An empty string on its own is not valid JSON. That's why there is an error from DataTables.
So the question then becomes, why is the server not responding with anything? Most likely there will be something shown in your server's error log stating what when wrong.
Allan
Hello Alan, thanks for the help, I was feeling ignored with this 'issue'.
Following your advice I searched on C:/Wamp/logs/php_error.log.
Howerever there was no error related with simple.html, ssp.class.php, or server_processing.php.
I checked others too, howerever only in acess.log there was some lines, like this:
Extra
I tried to create a new table called users_demo, with full data in all collumns howerever the error still prevailed.
Table Collumns:
id, name, email, city, age, sex, position
That's probably not the server error log. Does Wamp not have anything like apache/logs/error ?
You may also have to enable PHP's error logging if your system has it disabled.
Allan
@tangerine, I looked in C:/Wamp/errors. There are 4 error logs, apache, mysql, acess, and php. Only in acess, there was things related with datatables.
@allan, PDO and PHP error log are enabled.
Look at Apache's error log. Entries are timed so you can establish which is relevant to your last usage.
Look at Apache's error log. Entries are timed so you can establish which is relevant to your last usage.
Nothing relevant in apache_error.log @tangerine:
I made a test @allan, to see if PHP was working nice. 'echo $a'-> Undefined Index, error shown in the page and in php error log:
I'm not sure but maybe you can see the error, I'm not seeing.
Simple.html:
Server_Processing.php:
ssp.class.php is the same as github repo.
There is nothing obviously wrong with the code there. What version of PHP is your server running?
Could you try taking a debug trace and let me know what the debug code is please?
Thanks,
Allan
I used the datatables debugger already, just below the javascript initialization:
My first result is here:
debug.datatables.net/ujutog
And the second one I did now is:
debug.datatables.net/etizup
My server is WAMP, and I use Apache 2.4.23, PHP 7.0.10 and MySQL 5.7.14 in a Windows Server 2012.
That shows that
scripts/server_processing.php
is returning 200 OK, and an empty string. Which is weird, since it shouldn't be!What happens if you put a simple
echo "I am here";
immediately before calling the SSP class, but after the require? Is the echo shown in the return from the server?Allan
Just as you said @allan. The server response is "I am here". Strange that returns this, but not the database response. What I should do?
Is that not relevant?
Try putting it after the SSP class. My guess is that it won't be shown any more.
@tangerine - I think that's just a demo page that isn't present.
Allan
@allan, putting echo "I am here!"; after the require of SSP class, shows I am here in the XHR response in the console.
@tangerine - this was another test I did. It's irelevant for this issue. I am using the simple.html, not the PHP version
I'm not sure but maybe the error is related with the database. Here is my tbl_company table @allan:
Fields in red are those I wish to retrieve.
Okay - let's try this:
What does the browser show the server is returning now.
Sorry for the guess work!
Allan
It's returning the data @allan. But the error still continues. The data is not fetched in the table:
And JSONLint and JSONParser says that this(above) JSON is valid.
From {"draw": onwards is valid JSON, but what precedes it isn't.
Do you have any rogue "echo"s or other debug code anywhere?
My code is the same as here: https://datatables.net/forums/discussion/comment/113872/#Comment_113872
@tangerine
So what happens if you get rid of the var_dump() ?
Try it this way around:
The output above shows the
var_dump
first.Can you also use the debugger on it so I can see the data directly.
Allan
Hello @allan. I don't know how, when or who happened, but this morning suddenly my webpage was working nicely when I arrived, with the plugin correct and no errors.
I'm really amazed on what happened, but this issue has been closed for me, as there are no more erros reporting, not even through alerts or console.
Thank you, anyway or anyhow you made it works again.
Regards,
User
Your web server just needed a good nights rest
Hello again @allan. In my locahost machine everything worked fine. Howerever in the webserver (in production), I was updating there today and appeared:
I did the same as before howerever this time didn't magically fixed. Can you help one more time? The code is almost the same.
Here is a datatables debug:
https://debug.datatables.net/ajazig
The data is returning in the console, but not in the
<table>
, just as before.Here is an example JSON response:
My ssp.class is the same as the github, and my
<script>
tag have this code in the listCompany.php:My server_processing code is:
That's not valid JSON, which is why that error is being given.
Are you using a different version of PHP on your production server? If so, what version?
Allan
@User123456 are you using some word like "Irmãos" in your database?!
if yes watch this image and change in your ssp.class.php