开发者

How to redirect page on Jquery validation success [duplicate]

This question already has answers here: How do I redirect to another webpage? (58 answers) 开发者_Go百科 Closed 3 years ago.

I am using jquery for validation set some rules.

If validation success I want to redirect to another page. How can I do it?

// validate contact form on keyup and submit
$("#contactForm").validate({
    //set the rules for the field names
    rules: {
        name: {
            required: true,
            minlength: 2
        },
        email: {
            required: true,
            email: 4
        },

    },
    //set messages to appear inline
    messages: {
        name: "Please enter your name",
        password: "Please enter your email"
    }

});


Add your redirect logic in submitHandler callback. I think you want to set the window.url to a diff url. right?


Call window.location.replace='http://www.newpage.com';. Not jQuery specific.


Try adding a submitHandler option to validate like so:

$("#contactForm").validate({
   ...
   submitHandler: function(form) {    
      window.location = "http://your.url.here";
   }   
});

So when you validate the form, submitHandler is called if the form validated successfully, and there you redirect the user.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜