Reputation: 5107
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.
Upvotes: 2
Views: 76
Reputation: 5690
you can use this code for your problem
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
var ajaxid = 1;
$.ajax({
type: "POST",
url: "employee-grid-data.php",
data:{ ajaxid : ajaxid },
success: function(data){
console.log(data);
alert(data)
}
})
</script>
and your php file
<?php
echo $var = $_POST['ajaxid'];
?>
then you can see your ajaxid value , you can add ajaxid dynamic as your code
Upvotes: 0
Reputation: 156
Try:
ajax: "employee-grid-data.php?ajaxid=1"
and check Your $_GET['ajaxid']
Upvotes: 1