将详细信息发送到数据库后,正在将表单提交重定向到URL


Redirecting form submission to URL after sending the details to database

我正在进行弹出式时事通讯注册。我已经在另一个页面上有了类似的注册表格。我使用了确切的代码,它工作得很好。一旦我提交了表格,就必须执行两个操作。

  1. 将表单详细信息发送到数据库
  2. 正在重定向到感谢页面

使用现有的代码(这是来自电子商务网站,我无法操作代码),我可以将详细信息发送到数据库-非常好,但它不是重定向到谢谢页面,而是重定向到数据库中硬编码的页面(分配给"操作"。有办法吗?

这就是代码。

 <form name="MailingList" method="post" action="http://www.mywebsite.com/MailingList_subscribe.asp">  
     <input type="text" name="emailaddress" placeholder="Email Address" maxlength="100" size="28"> <br>
     <input type="submit" name="Submit"  value="Submit" width="260px">
 </form>

相反http://www.mywebsite.com/MailingListrongubscribe.asp,我想重定向到"www.mywebsite/谢谢.html"。如果我将www.mywebite.com/thankyou.html指定为"操作",则表单将重定向到"谢谢"页面,但不会将信息发送到数据库。我必须使用HTML,我不能从外部文件调用。我想我需要使用PHP,但我不清楚代码。

对不起,我脑子里到处都是,我想我已经解释清楚了。如果我的问题不清楚,我深表歉意。感谢

formId一样为表单提供id,您可以使用jQuery、

从jQuery repo下载jQuery最新版本,然后将jQuery.min.js文件放在resources文件夹中。

更新

<script src="yourResourcesFolderPath/jquery.min.js"></script>
// above code will use the jQuery plugin online
// chances are that the file path might be wrong according to where you put the js file
// A simple way to try this is put your file in the same folder of your html file and then change above code to
// <script src="jquery.min.js"></script> change file name according to downloaded file name.
<script>
    $(document).ready(function(){ // will run the below code after all html loaded 
        $('#formId').submit(function(){ // will be called upon form submission 
            $.ajax({
                type: "POST",
                url: "http://www.mywebsite.com/MailingList_subscribe.asp",
                context: document.body
            }).success(function() { 
                // this will be called when you return from your server submit code
                location.href = "www.mywebsite.com/ThankYou.html";
            });
        });
    )};
</script>