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.
The javascript function is fine. The problem is at the server side. You should write $_POST
, not $POST
.
echo "Name: ".$POST['name'];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With