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

时间:2014-09-18 05:19:23

标签: javascript php html

我正在制作一个弹出式简报注册。我已经在另一个页面中有类似的注册表单。我使用了确切的代码,效果很好。提交表单后,必须采取两项措施。

  1. 将表单详细信息发送到数据库
  2. 重定向到感谢页面。
  3. 使用现有代码(这是来自电子商务网站,我无法操纵代码),我可以将详细信息发送到数据库 - 完美的工作正常,但 它不会重定向到Thank You页面,而是重定向到数据库中硬编码的页面(分配给“action”。有没有出路?

    这是代码。

     <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/MailingList_subscribe.asp,我想重定向到“www.mywebsite / thankyou.html”。如果我将www.mywebsite.com/ThankYou.html分配给“action”,那么表单将被重定向到Thank页面,但不会将信息发送到数据库。我必须使用HTML,我无法从外部文件调用。我想我需要使用PHP,但我不清楚代码。

    抱歉,我的思绪到处都是,我想我已经清楚地解释了。如果我的问题不清楚,请道歉。感谢

1 个答案:

答案 0 :(得分:0)

formId提供表单ID,您可以使用jQuery,

执行此操作

JQuery repo下载jQuery最新版本,然后将jquery.min.js文件放在资源文件夹中。

<强>更新

<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>
相关问题