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

前端 未结 4 1994
盖世英雄少女心
盖世英雄少女心 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:24

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

        

    just give a class or ID to the submit button

        
    

    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.

提交回复
热议问题