使用jQuery validate提交表单后如何重定向

使用jQuery validate提交表单后如何重定向,jquery,jquery-plugins,Jquery,Jquery Plugins,我正在使用jqueryvalidate插件在提交联系人表单之前验证它 问题是,在成功提交表单后,我应该重定向到“谢谢”页面 这可能吗 我的验证代码如下所示: $("#contactForm").validate({ //debug: true, rules: { fullname: "required", email: { required: true, email: true } }, submitHandler: func

我正在使用jqueryvalidate插件在提交联系人表单之前验证它

问题是,在成功提交表单后,我应该重定向到“谢谢”页面

这可能吗

我的验证代码如下所示:

$("#contactForm").validate({
  //debug: true,

  rules: {

    fullname: "required",

    email: {
      required: true,
      email: true
    }
  },
  submitHandler: function(form) {
    form.submit();
    window.location.href = "/confirm.html";
  }

});
出于某种原因

window.location.href=/confirm.html

永远不会被执行

谢谢你的帮助


Anthony

经过一番尝试和错误,在将有效的表单提交到简单表单后,我设法重定向到“谢谢”页面。这必须通过ajax调用完成:

<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.12.0/jquery.validate.min.js"></script>
<script>
$("#contactForm").validate({
rules: {
    fullname: "required",
    email: {
      required: true,
      email: true
    }
  },

  submitHandler: function(form) {
    $.ajax({
      dataType: 'jsonp',
      url: "http://getsimpleform.com/messages/ajax?form_api_token=my-secret-token",
          data: $("#contactForm").serialize()
        }).done(function() {
      //callback which can be used to show a thank you message
      //and reset the form
      window.location.href = "/confirm.html";
    });
  }
});
</script>

不,我可以验证联系人表单并将其提交到简单表单服务,然后重定向到“谢谢”页面,所有这些都没有任何服务器端代码:smile:

这是因为您提交了表单,所以下面的行永远不会执行。要么使用ajax提交表单并根据是否成功重定向,要么在服务器端代码中重定向。谢谢Ashkan,你为我指明了正确的方向。幸运的是,简单表单服务能够通过Ajax提交表单