dqjcb132285 2014-09-18 05:19
浏览 69

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

I am working on a popup newsletter signup. I already have the similar signup form in another page. I used the exact code and it works great. Once I submit the form, two actions has to happen.

  1. Sending the form details to database
  2. Redirecting to thank you page.

With the existing code(this is from a ecommerce website, I cannot manipulate the code), I can send the details to database - perfectly works fine, but it is not redirecting to Thank You page, instead redirecting to the page hardcoded in the database(assigned to "action". Is there a way out?

This is the code.

 <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>

Instead of this - http://www.mywebsite.com/MailingList_subscribe.asp, I would like to redirect to "www.mywebsite/thankyou.html" . If I assign www.mywebsite.com/ThankYou.html to "action" , then the form is getting redirected to Thank you page, but not sending the information to the database. I have to use HTML, I cannot call from outside file. I guess I need to use PHP, but I am unclear with the code.

Sorry my mind is all over the place, I guess I explained it clearly. Apologies if my question is unclear. Thanks

  • 写回答

1条回答 默认 最新

  • duanpingzu7194 2014-09-18 05:25
    关注

    Give id to your form like formId and you can do this using jQuery,

    Download the jQuery latest version from JQuery repo and then place the jquery.min.js file in your resources folder.

    Updated

    <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>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?