Here is my code;
<script type="text/javascript">
function submitform()
{
$.post("handlers/request.php");
}
</script>
<form action="handlers/request.php" method="post" data-ajax="false" id="request">
<a href="javascript: submitform()">
<input type="hidden" name="url" value="http://google.com" />
</a>
</form>
In a separate PHP file (handers/request.php) I have a simple:
$url = $_POST['url'];
It isn’t picking this up. Why not?
You’re not actually passing any data through.
Note the second parameter, it’s an object which will carry our values over to the server-side PHP script. The
urlkey will become$_POST['url']on the server-end, and will contain our value from the[name='url']form input.Additionally, when binding this functionality to an anchor-click, avoid the following:
Instead, go with something more along the lines of:
Then, within your JavaScript:
It’s always good to keep your JavaScript out of your HTML.