How to redirect user to another page after Ajax form submission

前端 未结 7 596
既然无缘
既然无缘 2020-12-11 03:54

I\'m having problems redirecting the user to a thank you page after a successful form completion. What happens is that after the form submits, it goes to a blank page (https

相关标签:
7条回答
  • 2020-12-11 04:38

    Your success callback syntax is incorrect. It should rather be:

    $('#theForm').ajaxForm(function() { 
        window.location.href = "/path/to/thankyoupage";
    });
    

    Also, note that it is window.location.href and not location.window.href

    0 讨论(0)
  • 2020-12-11 04:44

    This is a jQUery Solution:

    window.location("www.example.com");
    
    0 讨论(0)
  • 2020-12-11 04:44
    //Please try this    
    <script src="http://malsup.github.com/jquery.form.js"></script> 
        <script> 
            $(document).ready(function() { 
                $('#theForm').ajaxForm(function() { 
                   alert('form was submitted');
                }); 
             success:function(response) {
                   if(response){ // check whether response is received
                        location.window.href = "http://your_domain_name/thank-you";}
                   }
            }); 
        </script> 
    
    0 讨论(0)
  • 2020-12-11 04:46

    you can try like this :

     success: function (data) {
        window.location.href = data.redirecturl;
    },
    error: function () {
        alert('error happened');
    }
    
    0 讨论(0)
  • 2020-12-11 04:53

    The follow code worked for me, in a complete different context of the OP:

    $(document).ready(function() {
      window.location.href = "URL";
      });

    0 讨论(0)
  • 2020-12-11 04:56

    Should be

    window.location = "http://www.google.com";
    
    0 讨论(0)
提交回复
热议问题