开发者

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

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. However, I've already got my own ajax submission functions that I don't want to rewrite.

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 clicke开发者_高级运维d, the page reloads.


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.

Hope this helps. Cheers


Depending on how the submitHandler is attached to the form submission event, you could try adding return false; at the end of the function body.


Add a return false at the end of function myAjaxSubmissionFunction.


There is an ajax form plugin for jquery.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜