DataTable waring: table id=lodgeList - Invalid JSON response - After transfered to other server
DataTable waring: table id=lodgeList - Invalid JSON response - After transfered to other server
Hello everyone
I am here a new and I would like to ask for help regarding one issue regarding "datables ajax"
After transferring it from one server to another, I am facing an issue with my system. We can see the list of records (old_server.jpg)
Upon logging in, you should see a list of lodges displayed via the integration of: https://datatables.net/
The transferred files are now located on the
new server. However, upon logging in, I am encountering an error that states there are no records of lodges and I am receiving the following error message (new_server.jpg):
"DataTables warning: table id=lodgeList - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1"
As well In my error_log I am also getting these SESSION errors :
[29-Aug-2024 19:50:41 UTC] PHP Warning: Undefined array key "name" in /home/victor21/public_html/victoria/database/menus.php on line 23
[29-Aug-2024 19:54:39 UTC] PHP Warning: session_start(): open(/var/cpanel/php/sessions/alt-php70/sess_1462d20a1b1fdfcb05fb6980bc96ee71, O_RDWR) failed: No such file or directory (2) in /home/victor21/public_html/victoria/database/lodge.php on line 3
[29-Aug-2024 19:54:39 UTC] PHP Warning: session_start(): Failed to read session data: files (path: /var/cpanel/php/sessions/alt-php70) in /home/victor21/public_html/victoria/database/lodge.php on line 3
[29-Aug-2024 19:54:39 UTC] PHP Warning: Undefined array key "name" in /home/victor21/public_html/victoria/database/menus.php on line 23
I asked my new server provider but he messaged me back that their server is configured correctly and no issue from their site.
I will grateful for any advice to fix it
Many thanks
Lukasz
This question has an accepted answers - jump to answer
Answers
There isn't anything Datatables can do to fix these errors. They are errors coming from your server script. It will require debugging on the server to track down the errors. Without seeing any configuration info its impossibly to guess which, if any, of those errors are resulting in the JSON error.
Did you follow the troubleshooting steps provided at the link in the error?
https://datatables.net/manual/tech-notes/1
What is in the XHR response?
Post your Datatables config.
Kevin
Hi Kevin
Thank you for your quick response.
Yes, I followed the troubleshooting steps but without luck.
My XHR response is (new_server.jpg):
" No response data available for this request"
Here is datatables config:
$(document).ready(function() {
});
I appreciate your help
Lukasz
The errors you posted above seem to be from other scripts since your
ajax.url
isaction.php
. They might eb indirectly related depending on whataction.php
does. The error is due to not receiving anything in the response.Are you using a Datatables supplied server side processing script or your own script?
The
action.php
script will need to be debugged to determine why its not sending JSON in the response.Kevin
I looked at the screenshot again for the Status code but its cutoff. What is the response code?
Kevin
Thank you for your reply
So in action.php I have this code:
<?php
session_start();
include 'Inventory.php';
$inventory = new Inventory();
if(!empty($_GET['action']) && $_GET['action'] == 'logout') {
session_unset();
session_destroy();
header("Location:index.php");
}
if(!empty($_POST['action']) && $_POST['action'] == 'lodgeList') {
<?php > ?>$inventory->getLodgeList();
}
and inside Inventory.php I have this class :
of course, on the top of this Inventory.php, I got configuration with database: user, password, database and etc
Many thanks for more advice
Lukasz
Have you check the server's PHP error log?
Yes, checked and don't have none server's PHP errors
That means that the server isn't returning anything (which in turn isn't valid JSON - hence the error). If there is no PHP error that is stopping the response, then you need to check the logic in your PHP script to see why it isn't returning anything. It isn't immediately apparent to me from the above function why it wouldn't be returning anything.
Allan
Thank you for reply
I dont know if read my first post that on my old server everything was working but when I transferred to another server (krystal.io) is not working so that confused meβ¦.
Lukasz
Yup, which continues to suggest that the problem is with your php script, or perhaps the database connection or similar. It isnt a JavaScript DataTables issue. The debugging needs to be done at the server side. I'm surprised there is no error in the error log.
Allan
The file action.php is working fine, but when I modified the file Inventory.php and class getLodgeList() and put only one: echo "test," I can see the response AJAX with title Test.
so we should modify this part of the code:?
public function getLodgeList(){
echo json_encode($output);
}
In class getLodgeList() I changed :
echo json_encode($output)
to
var_dump($output)
so can see a response with records from the database (attached picture)
so maybe we should modification this part:
$output = array(
"draw" => intval($_POST["draw"]),
"recordsTotal" => $numRows,
"recordsFiltered" => $numRows,
"data" => $customerData
);
to get this work?
Thanks
Lukasz
Maybe this article will help you debug why json_encode seems to be returning an empty result.
Kevin
Thank you for the articel. Just did first step and added first code:
echo json_last_error_msg(); // Print out the error if any
die(); // halt the script
and yes i got a message :
"Malformed UTF-8 characters, possibly incorrectly encoded"
so I have to modify this bit:
$output = array(
"draw" => intval($_POST["draw"]),
"recordsTotal" => $numRows,
"recordsFiltered" => $numRows,
"data" => $customerData
);
echo json_encode($output);
so instead I used this one :
$output = array(
"draw" => intval($_POST["draw"]),
"recordsTotal" => $numRows,
"recordsFiltered" => $numRows,
"data" => $customerData
);
echo json_encode($output, JSON_UNESCAPED_UNICODE);
but still, I am getting this error :
"Malformed UTF-8 characters, possibly incorrectly encoded"
Did I modify it wrong?
Lukasz
I suspect you will need to dig into why this error is occurring. Guessing something with the server transfer has caused the issue. Maybe a DB version change or data migration issue. Its hard to say without knowing what was involved.
This is not a Datatable issue and is beyond the scope of this forum. You will find more resources for your error on forums like Stack Overflow. Doing a Google search of the error and json_encode results in lots of Stack Overflow and other threads like this.
Kein
Thank you for the article link:
I updated to :
echo json_encode($output, JSON_INVALID_UTF8_IGNORE);
and is working
Many thanks to everyone to helping me
Thanks
Glad you got it worked out!
Kevin