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 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序