开发者

jQuery validate with .post

I am using the jQuery validate plug-in to validate a form and if it validates I would like to post the data.

Below is the code I have so far. How can I change code so that the post only happens if the form validates? Currently it posts the data regardless of whether it's valid or not...which is not what I want to happen.

$("#next_architect").live("click",function() {
    $("#architect_form").valid();
    $.post('scripts/register_user.php', 
        $("#architect_form"开发者_StackOverflow).serializeArray(), function(data) {
            alert("inserted");
        }
    );
});

Can someone point me in the right direction?


You may want to do:

if( $("#architect_form").valid() ) { /* post code */ }


You want to setup a success handler:

$(".selector").validate({
   submitHandler: function(form) {
       // do other stuff for a valid form
    form.submit();
   }
});

http://docs.jquery.com/Plugins/Validation/validate#toptions

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜