JavaScript:发送POST,重定向到响应 [英] JavaScript: Sending POST, redirecting to response
本文介绍了JavaScript:发送POST,重定向到响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一张带有onclick的图像。当click事件触发时,我想发送一个HTTP POST并让window.location重定向到POST的响应。我该怎么做?
I have an image with an onclick. When the click event fires, I want to send an HTTP POST and have the window.location redirect to the response to the POST. How can I do that?
推荐答案
只需将按钮绑定到表单元素的submit方法,重定向就会自然发生。
Just bind the button to the submit method of a form element, and the redirect will happen naturally.
<script type='text/javascript'>
function form_send(){
f=document.getElementById('the_form');
if(f){
f.submit();
}
}
</script>
<form method='post' action='your_post_url.html' id='the_form'>
<input type='hidden' value='whatever'>
</form>
<span id='subm' onclick='form_send()'>Submit</span>
这篇关于JavaScript:发送POST,重定向到响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文