I am using following JS to get JSON array from a PHP file:
<script type="text/javascript" language="javascript" >
$(document).ready(function() {
var dataTable = $('#employee-grid').DataTable( {
processing: true,
serverSide: true,
ajax: "employee-grid-data.php", // json datasource
language: {
processing: "Procesando datos...",
search: "Buscar:",
lengthMenu: "Mostrar _MENU_ doctores/as",
info: "Mostrando del doctor/a _START_ al _END_ de un total de _TOTAL_ doctores/as seleccionados" ,
infoEmpty: "Mostrando doctor/a 0 al 0 de un total de 0 doctores/as",
infoFiltered: "(filtrados de _MAX_ doctores/as)",
infoPostFix: "",
loadingRecords: "Procesando datos...",
zeroRecords: "No hay doctores/as que cumplan los criterios",
emptyTable: "Noy hay datos que cumplan los criterios",
paginate: {
first: "Primero",
previous: "Anterior",
next: "Siguiente",
last: "Ultimo"
},
aria: {
sortAscending: ": activer pour trier la colonne par ordre croissant",
sortDescending: ": activer pour trier la colonne par ordre décroissant"
}
}
} );
var colvis = new $.fn.dataTable.ColVis( dataTable, {
buttonText: '<img src="images/down.gif" >',
activate: 'mouseover',
exclude: [ 0 ]
} );
$( colvis.button() ).prependTo('th:nth-child(1)');
} );
</script>
It is working fine. Now I need to send parameters to the PHP file, I have tried adding this to the script,just below the ajax:url line:
type: "get", //send it through get method
data:{ajaxid:"1"},
and then including this in the PHP to catch the params:
$var = $_GET['ajaxid'];
but I get 'null' for $var. I have also tried using POST method instead of GET method, but same result.
json_decode(file_get_contents('php://input'), true);. What is the output when you decode it. Can you show your full js code for sending the request ?