How do I redirect using either JQuery, DOJO or plain JavaScript, load another page but sent some POST parameters in request?
This should work, but i haven't tested it:
function postData(url, data)
{
var form = $('<form></form>');
$(form).hide().attr('method','post').attr('action',url);
for (i in data)
{
var input = $('<input type="hidden" />').attr('name',i).val(data[i]);
$(form).append(input);
}
$(form).appendTo('body').submit();
}
Basically you can create a form on the fly and submit it. Unfortunately you can not POST stuff directly from script.
You can't redirect with postdata using JavaScript, and I'm sure it's the same for jQuery as well. However, what you can do is...have a hidden form with post data, manipulate it as you need in javascript and submit that form.
<form id="myform" method="post" action="mypage.php">
<input id="myinput" type="hidden" value="mydata" />
</form>
<script type="text/javascript">
// in some function...
document.getElementById("myform").submit();
</script>
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