I have a problem with jQuery and PHP… so here is my jQuery code:
var rino = "Renaro";
$(document).ready(function() {
$.post('form.php', { test: rino } );
});
and here PHP
echo $_POST['test'];
From documentation I understood that after jQuery there should be assigned rino value to $_POST['test'].. But it doesn’t echo’s value.. and gives PHP error PHP Notice: Undefined index: test
What am I doing wrong?
Here is full code of file
<html>
<head>
<script type="text/javascript" src="jquery.js" ></script>
<script type="text/javascript">
var rino = "Renaro";
$(document).ready(function() {
$.post('form.php', { "test" : "rino" } );
});
</script>
</head>
<body>
<div id="content">
<?php echo $_POST['test']; ?>
</div>
</body>
</html>
If you change your code to this, that should work.
Note that I remove the quote from
rinobecause it’s a variable.