Jun*_*une 8 html javascript forms ajax redirect
在成功完成表单后,我在将用户重定向到感谢页面时遇到问题.结果是,在表单提交之后,它会转到一个空白页面(https://cunet.sparkroom.com/Sparkroom/postLead)...我需要将其重定向到感谢页面,同时将表单详细信息提交给"表单操作"中的URL.
HTML代码:
<form action="https://cunet.sparkroom.com/Sparkroom/postLead/" method="post" name="theForm"
id="theForm" onSubmit="return MM_validateForm();" >
...
</form>
Run Code Online (Sandbox Code Playgroud)
Ajax代码:
<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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
有谁知道我做错了什么?我需要表单将数据提交到URL,然后将用户重定向到"谢谢"页面
tec*_*bar 15
您的成功回调语法不正确.它应该是:
$('#theForm').ajaxForm(function() {
window.location.href = "/path/to/thankyoupage";
});
Run Code Online (Sandbox Code Playgroud)
另外,请注意它是否window.location.href存在location.window.href