2

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.

7
  • When you var_dump($_GET), what is the output ? Commented Aug 10, 2016 at 7:41
  • @VasilShaddix, let me try Commented Aug 10, 2016 at 7:42
  • @VasilShaddix, I also get null Commented Aug 10, 2016 at 7:44
  • What about 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 ? Commented Aug 10, 2016 at 7:45
  • @VasilShaddix, the full js code is already in the question Commented Aug 10, 2016 at 7:47

2 Answers 2

1

Try:

ajax: "employee-grid-data.php?ajaxid=1"

and check Your $_GET['ajaxid']

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.