如何重定向用户到阿贾克斯表单提交后,另一页表单、重定向、用户、提交后

2023-09-11 22:28:23 作者:念旧.

我有问题,一个成功的形式完成后把用户重定向到一个感谢您网页。什么情况是,表单提交后,它关系到一个空白页( https://cunet.sparkroom.com / Sparkroom / postLead )...我需要它重定向到一个感谢页面,同时提交的表单操作的形式详细信息的URL。

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://cunet.sparkroom.com/Sparkroom/postLead)... I need it to redirect to a thank you page while submitting the form details to the URL in the 'form action'.

HTML code:

HTML Code:

<form action="https://cunet.sparkroom.com/Sparkroom/postLead/" method="post" name="theForm" 
id="theForm" onSubmit="return MM_validateForm();" >
...
</form>

阿贾克斯code:

Ajax Code:

<script src="http://malsup.github.com/jquery.form.js"></script> 
<script> 
    $(document).ready(function() { 
        $('#theForm').ajaxForm(function() { 
           alert('form was submitted');
        }); 
     success:function(response) {
           location.window.href = "redirect user to the thank you page";
                }
    }); 
</script> 

JavaScript的:

JavaScript:

function MM_validateForm() {
if ( !jQuery('#theForm #FirstName').val() ) {
alert('Please input your first name.');
jQuery('#theForm #FirstName').focus();
return false;
}
if ( !jQuery('#theForm #LastName').val() ) {
alert('Please input your last name.');
jQuery('#theForm #LastName').focus();
return false;
}
if ( !jQuery('#theForm #daytimephone').val() ) {
alert('Please input your phone number.');
jQuery('#theForm #daytimephone').focus();
return false;
}
if ( !jQuery('#theForm #Email').val() ) {
alert('Please input your email.');
jQuery('#theForm #Email').focus();
return false;
}
if ( !jQuery('#theForm #BID').val() ) {
alert('Please select your preferred campus.');
jQuery('#theForm #BID').focus();
return false;
}
if ( !jQuery('#theForm #programs').val() ) {
alert('Please select your preferred program.');
jQuery('#theForm #programs').focus();
return false;
}
if ( !jQuery('#theForm #How_Heard').val() ) {
alert('Please select how you heard about us.');
jQuery('#theForm #How_Heard').focus();
return false;
}
return true;
}
// ]]></script>

有谁知道我在做什么错了?我需要的形式将数据提交给URL,然后后用户重定向到一个谢谢页

Does anyone know what I'm doing wrong? I need the form to submit the data to the URL and then after redirect the user to a 'thank you' page

推荐答案

您成功的回调语法不正确。它应该是:

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

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

另外请注意,这是 window.location.href ,而不是 location.window.href