javascript - How to redirect user to another page after Ajax form submission -


i'm having problems redirecting user thank page after successful form completion. happens after form submits, goes blank page (https://cunet.sparkroom.com/sparkroom/postlead)... need redirect thank page while submitting form details url in 'form action'.

html code:

<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 submitted');         });       success:function(response) {            location.window.href = "redirect user thank page";                 }     });  </script>  

javascript:

function mm_validateform() { if ( !jquery('#theform #firstname').val() ) { alert('please input first name.'); jquery('#theform #firstname').focus(); return false; } if ( !jquery('#theform #lastname').val() ) { alert('please input last name.'); jquery('#theform #lastname').focus(); return false; } if ( !jquery('#theform #daytimephone').val() ) { alert('please input phone number.'); jquery('#theform #daytimephone').focus(); return false; } if ( !jquery('#theform #email').val() ) { alert('please input email.'); jquery('#theform #email').focus(); return false; } if ( !jquery('#theform #bid').val() ) { alert('please select preferred campus.'); jquery('#theform #bid').focus(); return false; } if ( !jquery('#theform #programs').val() ) { alert('please select preferred program.'); jquery('#theform #programs').focus(); return false; } if ( !jquery('#theform #how_heard').val() ) { alert('please select how heard us.'); jquery('#theform #how_heard').focus(); return false; } return true; } // ]]></script> 

does know i'm doing wrong? need form submit data url , after redirect user 'thank you' page

your success callback syntax incorrect. should rather be:

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

also, note window.location.href , not location.window.href


Comments