Can't load data from php
Can't load data from php
I'm using dataTable 1.10.
I'm trying to load the data with ajax and php, but i get the alert: "invalid JSON response".
I've paste the code i get from ajax on json.lint and is this:
{
"data": [{
"nombreCliente": "Juan Perez",
"nit": "78945641",
"ci": "558888"
}]
}
Even with the values "draw", "recordsTotal" and "recordsFiltered" in top of the json result I still getting the same alert error.
My script code:
$(document).ready(function(){
var table = $('#dataTables-example').DataTable( {
"processing": true,
"serverSide": true,
"ajax" : "obtener_clientes.php",
"columns": [
{ "data": "nombreCliente" },
{ "data": "nit" },
{ "data": "ci" }
],
} );
});
I have no idea what's wrong whit this.
Answers
try this on your php script
header('Content-Type: application/json');
print json_encode($json_data);
without the header the content type probably was set to text/html
use live HTTP requester if you use firefox to check the proper header sent by your server side scripting language
loloski, thanks for answer. Json.lint says my json code is ok, I tried what you suggets but I still getting the same alert error "Datatables warning: table id=table JSON invalid response"
I will try another version of datatable