Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery.post() - Trouble sending post data

Tags:

jquery

php

I have a html file with the following javascript code to call the jquery.post function and post some data to test.php

<script type="text/javascript">
      $.post("test.php", { name: "John", time: "2pm" }, function(data) {
         alert("Data Loaded: " + data);
       });
</script>

test.php is as follows

<?php
   echo "Name: ".$POST['name'];
?>

Unfortunately, my alert only shows "name: " without sending back the post data.

Using firebug, however, I can see that the post data is in fact being sent. So I'm very confused as to why $POST isn't working in my php file.

like image 375
icarus Avatar asked Jan 02 '13 01:01

icarus


1 Answers

The javascript function is fine. The problem is at the server side. You should write $_POST, not $POST.

echo "Name: ".$POST['name'];
like image 119
Stanley Avatar answered Oct 10 '22 20:10

Stanley