How do I POST variables using jQuery / Javascript to another page?
How do I use POST using jQuery/Javascript to send to another page and redirect to that page?
Sending variables using GET...
In Javascript
window.location = 'receivepage.php?variab开发者_如何学编程le='+testVariable;
When it is receive by PHP...
$var = $_GET['variable'];
How do I do that ^ , using $_POST?
I already tried...
$.post(
'receivepage.php', {
i: i
}, function(){
window.location = 'receivepage.php';
}
);
but it seems to lose the variable when it reaches PHP
Doing $.post is trying to post the information via ajax, and THEN redirecting to your page, so when you finally get there, the attribute "i" won't be received.
You could do someothing like this:
HTML
<form method="post" target="receivepage.php" id="myform">
<input type="hidden" name="i" value="blah" />
</form>
JS
<script type="text/javascript">
$("#myform").submit();
</script>
Does that solve your problem?
Edit
If your value comes from JS, you can add it like this:
JS
<script type="text/javascript">
$('#myform input[name="i"]').val(i);
$("#myform").submit();
</script>
According to your example, "i" is defined on the window scope, making it global and accessible from this script.
In your post example, $_POST['i'], would be your variable.
精彩评论