简体   繁体   中英

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. 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"; 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";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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