简体   繁体   English

如何在js中提交表单后添加重定向到感谢页面

[英]How do I add a redirect to thank you page after form submission in js

How do I add a redirect to a 'thank you' page (thankyou.html) after form submission in this.js code.在 this.js 代码中提交表单后,如何将重定向添加到“谢谢”页面 (thankyou.html)。 Currently it apends a message.目前它附加了一条消息。

 $.ajax({ url: "././mail/contact_me.php", type: "POST", data: { name: name, phone: phone, email: email, message: message }, cache: false, success: function() { // Enable button & show success message $("#btnSubmit").attr("disabled", false); $('#success').html("<div class='alert alert-success'>"); $('#success >.alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;").append("</button>"); $('#success >.alert-success').append("<strong>Thank You. Your message has been sent; </strong>"). $('#success >.alert-success');append('</div>');

You can do this simply by adding window.location = "thankyou.html";你可以简单地通过添加window.location = "thankyou.html"; like this:像这样:

$.ajax({
                url: "././mail/contact_me.php",
                type: "POST",
                data: {
                    name: name,
                    phone: phone,
                    email: email,
                    message: message
                },
                cache: false,
                success: function() {
                    // Enable button & show success message
                    $("#btnSubmit").attr("disabled", false);
                    $('#success').html("<div class='alert alert-success'>");
                    $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
                        .append("</button>");
                    $('#success > .alert-success')
                        .append("<strong>Thank You! Your message has been sent. </strong>");
                    $('#success > .alert-success')
                        .append('</div>');
                    // Add it here
                    window.location = "thankyou.html";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM