Ich habe Probleme, den Benutzer nach erfolgreichem Ausfüllen des Formulars auf eine Dankeseite umzuleiten. Was passiert, ist, dass nach dem Senden des Formulars eine leere Seite angezeigt wird ( https://cunet.sparkroom.com/Sparkroom/postLead ) ... Formulardetails zur URL in der "Formularaktion".
HTML Quelltext:
<form action="https://cunet.sparkroom.com/Sparkroom/postLead/" method="post" name="theForm"
id="theForm" onSubmit="return MM_validateForm();" >
...
</form>
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:
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>
Weiß jemand, was ich falsch mache? Ich brauche das Formular, um die Daten an die URL zu übermitteln und den Benutzer anschließend auf eine Dankeseite umzuleiten
Ihre Erfolgsrückrufsyntax ist falsch. Es sollte eher sein:
$('#theForm').ajaxForm(function() {
window.location.href = "/path/to/thankyoupage";
});
Beachten Sie auch, dass es window.location.href
und nicht location.window.href
ist.
//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>
Dies ist eine jQUery-Lösung:
window.location("www.example.com");
du kannst es so versuchen:
success: function (data) {
window.location.href = data.redirecturl;
},
error: function () {
alert('error happened');
}
Der folgende Code funktionierte für mich in einem völlig anderen Kontext des OP:
$(document).ready(function() {
window.location.href = "URL";
});
Du solltest benutzen
window.location.href = "http://www.google.com";
und nicht
location.window.href = "http://www.google.com";
http://www.w3schools.com/js/js_window_location.asp
Der Erfolg sollte eine Funktion sein, die als Argument an $ .ajaxForm übergeben wird:
$('#theForm').ajaxForm(function() {
window.location.href = "redirect user to the thank you page";
});