How to redirect user to another page after Ajax form submission?

前端 未结 4 1940
盖世英雄少女心
盖世英雄少女心 2021-01-21 03:51

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://c

相关标签:
4条回答
  • 2021-01-21 04:06

    There are two way to redirect user after successful form post.

    1) You can put a on Success event in ajax submission in which you can simply redirect user to thankyou page.

    2) Use a server side function after your form post processing done For Ex in PHP:

    header("Location: http://thankyoupage.html");
    
    0 讨论(0)
  • 2021-01-21 04:15

    Try:

    $('#theForm').ajaxForm(function() { 
     success : function(){
        window.location.href = "Url to redirect here in the success option";
     }
    });
    
    0 讨论(0)
  • 2021-01-21 04:17

    Try

    window.location.href = "http://www.msdn.com";
    
    0 讨论(0)
  • 2021-01-21 04:24

    You could hadle the submit post with jquery, so you will have to cancel the action in the form

        <form  name="theForm" id="theForm" >
    

    just give a class or ID to the submit button

        <submit class='submitTheForm'....>
    

    the code will be like this.. you just need to include all the form variables with the right name.

    Then add the jquery post request at the bottom of MM_validateForm()

        if ( !jQuery('#theForm #How_Heard').val() ) {
        alert('Please select how you heard about us.');
        jQuery('#theForm #How_Heard').focus();
        return false;
        }
    
        $.post("https://cunet.sparkroom.com/Sparkroom/postLead/",
    {
    FirstName:FirstName,
    LastName:LastName
        ...
        ...
    },
    function(){
        window.location.href = 'thank you page'
        }
    });
    

    And finally call the function MM_validateForm() when the submit button get clicked

        $('.submitTheForm').click( function(){
        MM_validateForm();
        });
    

    jquery post from http://api.jquery.com/jQuery.post/ the rest from personal experience.

    0 讨论(0)
提交回复
热议问题