-1

## This My test.php file ##

 //here I am getting the variable value

<?PHP
 $name = $_POST('variable');
 echo $name;
?>

## This my script ##

 //avariable value passing to test .php file

<script type ="text/javascript">
  var name = "jani";
  $.ajax({
          type: 'POST',
          url: 'test/test.php',
          data: {'variable': name},
          });
</script>

###** I am getting this error **###

 Fatal error: Function name must be a string in 
                 D:\xampp\htdocs\test\test.php on line 2
Jaymin
  • 1,643
  • 1
  • 18
  • 39
Jani
  • 19
  • 1
  • 6

2 Answers2

1

Change your test.php code use square bracket not round for super global variable as below,

<?php
if (isset($_POST['variable'])) {
    $name = $_POST['variable'];
    echo $name;
}
?>
Narayan
  • 1,670
  • 1
  • 19
  • 37
0

Try this it will definitely work: My PHP File:

<script>
var name = "name";
var url = "test/test.php";
        $.ajax({
            url: url,
            type: 'POST',
            data: {'name': name},
           success: function (data) {
            console.log(date);
           }
});
</script>

Where ajax request recieves:

//here I am getting the variable value

<?PHP
 $name = $_POST['name'];
 echo $name;
?>

After Your latest comment I have added js fiddle link before running it open console and POST besides headers section you can see data has been posted. Js Fiddle Demo Link

Jaymin
  • 1,643
  • 1
  • 18
  • 39