在用户提交表单后重定向用户

Redirecting users after they submit a form

本文关键字:用户 重定向 提交 表单      更新时间:2023-09-26

我试图使一个基本的形式,重定向用户到任何给定的网页,我选择后,他们提交他们的响应。尽管action元素位于我无法操作的站点上。

我该怎么做呢?

<form method="POST" action="https://docs.google.com/forms/d/1dAp52ALtiu8tEt8UY-Rs7WcKn36pI1vBItmGl0sV0Ik/formResponse">
<input type="text" name="entry.139518212" value="">
<input type="submit" name="submit" value="Submit">
</form>

Ajax可能对您有帮助。您可以通过Ajax提交表单,获取响应并做任何您想做的事情。你必须创建一个ajax函数并在点击事件

时调用它
<input id="text" type="text" name="entry.139518212" value="">
<input type="submit" name="submit" value="Submit" onclick="sendData();">
然后创建一个js函数:
function sendData(){
///getting text from input
text=document.getElementById('text').value;
var xmlhttp;
///browser compatibility
if (window.XMLHttpRequest){
    xmlhttp=new XMLHttpRequest();
}else{
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
    ///if response was retrieved and no errors occured
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
      ///you can access the response
      ///put your redirection code here
    }
}
xmlhttp.open("POST","https://docs.google.com/forms/d/1dAp52ALtiu8tEt8UY-Rs7WcKn36pI1vBItmGl0sV0Ik/formResponse",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("entry.139518212="+text);
}

试试这个。您需要使用jQuery才能使其工作。

<script type="text/javascript">
    $(function() {
      $('form').submit(function(){
        $.post('https://docs.google.com/forms/d/1dAp52ALtiu8tEt8UY-Rs7WcKn36pI1vBItmGl0sV0Ik/formResponse', function() {
          window.location = 'http://www.whereveryouwanttogo.com';
        });
        return false;
      });
    });
</script>

From HTML Form Redirect