I have an issue with encoding json to sent to datatable.net. I received DataTables warning: "table id=varietyTable - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1." Checked the development tool. I found out that there is no response. There apparently there is something wrong with json_encode. I look at the record. it seems to have problem handing ascii code 160. The same code running on my local machine (running xampp). There is no problem.
I tried to echo the page. I see unreadable character on the remote server but no local host. output on remote server: Alma�� output on local host: Alma (note that there are spaces behind the word Alma).
The php code are identical. I am just wondering whether the local php setting is different so that the special characters can handle properly.
Thanks.
here are some code from php code that receiving the records and return as Json. The code is rather long. I am posting the parts the fetch the records and return as json. The error message is already posted above: Invalid Json response (in fact. there is no response). It happens whenever I navigate to the records containing the special characters. Again, I only got the error on the remote host, not on the local host. That leads me believe that it's the configuration issue because the source code on the localhost and remote machine are identical.
$totalQuery = mysqli_query($conn, $sql);
$totalRowCount = mysqli_num_rows($totalQuery);
if($_POST['length'] != -1){
$start = $_POST['start'];
$length = $_POST['length'];
$sql .= " LIMIT " . $start . ", ". $length;
}
$filteredQuery = mysqli_query($conn, $sql);
$filteredRowCount = mysqli_num_rows($filteredQuery);
$data = array();
$counter;
while($row = mysqli_fetch_assoc($filteredQuery))
{
$counter += 1;
$sub_array = array();
$sub_array[] = $row['variety_name'];
$sub_array[] = $row['abbreviation'];
$sub_array[] = $row['fig_family_name'];
$sub_array[] = $row['variety_id'];
$data[] = $sub_array;
}
$output = array(
'draw'=> intval($_POST['draw']),
'recordsTotal' =>$totalRowCount,
'recordsFiltered'=>$totalRowCount,
'data'=>$data,
);
echo json_encode($output);
source https://stackoverflow.com/questions/70502505/php-handling-character-set
Comments
Post a Comment