1

I'm trying to use Data-tables but I need to pass a value from Ajax to PHP file.

the Ajax part is like this:

<script>
    $(document).ready(function() {

        var oTable =
            $('#user-list').DataTable({
                "serverSide": true,

                "ajax": {
                    "url": "assets/server_processing_reminders.php",
                    "data": {
                        "CurrentFlag": 1
                    }
                },

                "columnDefs": [{
                    "width": "6%",
                    "targets": 0
                }],


                "order": [
                    [1, "asc"]
                ]

            });


    });
</script>

on the server side Im trying to get the variable "CurrentFlag" using:

<?php

if (isset($_GET["CurrentFlag"])){
    $cf = $_GET["CurrentFlag"];
}

echo $cf;

but the php file is not printing out the value send. Thanks for any help

6
  • Try $_REQUEST["CurrentFlag"]; Commented Dec 28, 2017 at 6:07
  • Jquery server side datatable only work with ajax "POST" method Commented Dec 28, 2017 at 6:26
  • phppot.com/php/… Commented Dec 28, 2017 at 6:34
  • You need to provide request type as "GET" as shown here :- "ajax" : { "url": "assets/server_processing_reminders.php", type: "GET", "data": { "CurrentFlag": 1 } } Commented Dec 28, 2017 at 8:43
  • @SanalS that seems to work! Commented Dec 28, 2017 at 15:18

3 Answers 3

1

Please use $_REQUEST instead of $_GET like this :

 if(isset($_REQUEST["CurrentFlag"]))
  {
    $cf = $_REQUEST["CurrentFlag"];

   }

   echo $cf;

OR

If you want print data using $_GET method please add type:GET under ajax call

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

Comments

1

You need to provide request type as GET as shown here.

"ajax" : { 
    "url": "assets/server_processing_reminders.php", 
    type: "GET", 
    "data": { 
            "CurrentFlag": 1 
    } 
}

Comments

0

Use Jquery for better code and results.

Learn Ajax using this link :

https://www.w3schools.com/js/js_ajax_intro.asp

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.