繁体   English   中英

jQuery提交表单后如何重定向

[英]how to redirect after form submission with jQuery validate

我正在使用jQuery validate插件在提交联系表单之前对其进行验证。

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

这可能吗?

我的验证代码如下所示:

$("#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”);

永远不会执行。

谢谢你的帮助,

安东尼

经过一番尝试和错误之后,在将表单提交到简单表单后,我设法重定向到“谢谢”页面。 这必须通过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:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM