简体   繁体   English

可以返回使用 validate.js 提交表单而不重新加载页面吗?

[英]Possible to return use validate.js to submit a form without reloading the page?

I'm using Jörn Zaefferer's validate plugin for jquery我正在为 jquery 使用 Jörn Zaefferer 的验证插件

http://bassistance.de/jquery-plugins/jquery-plugin-validation/ http://bassistance.de/jquery-plugins/jquery-plugin-validation/

Is it possible to use this plugin to validate a form, and have the page not reload when the form is submitted?是否可以使用此插件验证表单,并在提交表单时不重新加载页面?

The plugin, when used ajaxform, allows you to submit the contents of the form via ajax.该插件在使用 ajaxform 时允许您通过 ajax 提交表单的内容。 However, I've already got my own ajax submission functions that I don't want to rewrite.但是,我已经有了自己的 ajax 提交函数,我不想重写。

So far, I've got something like this:到目前为止,我有这样的事情:

$("#myform").validate({
        submitHandler : function(form){
            myAjaxSubmissionFunction() ;
        }
    });

This is fine, but when validation passes and the submit button is clicked, the page reloads.这很好,但是当验证通过并单击提交按钮时,页面会重新加载。

Depending on how the submitHandler is attached to the form submission event, you could try adding return false;根据submitHandler如何附加到表单提交事件,您可以尝试添加return false; at the end of the function body.在 function 主体的末端。

There is an ajax form plugin for jquery . jquery 有一个ajax 表单插件

I think you should add this:我认为你应该添加这个:

$("#myform").submit(function(event){
   event.preventDefault();
});

This will prevent the form to be submitted normally, so only your ajax submission will run.这将阻止表单正常提交,因此只有您的 ajax 提交会运行。

Hope this helps.希望这可以帮助。 Cheers干杯

Add a return false at the end of function myAjaxSubmissionFunction .在 function myAjaxSubmissionFunction末尾添加return false

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

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