How to change a form's containing div after validation & submission?

I have a form that validates using jquery. The form's id is "contact" and it's inside of a div called "formdiv". I want it to, on submit, instead of taking me to a new page "contact_received.php", replace the contents of "formdiv" with the contents of "contact_received.php" including the submitted $_GET data. (e.g.: echo 'thank you, '.$_GET['name'].' for contacting us, we'll get back to you about '.$_GET['message']). I looked for something similar online & figured I would use jquery submit handler: $("#contact").validate({ rules: {SOME RULES-clipped for length}, messages: {SOME MESSAGES-clipped for length}, submitHandler: function() { $.ajax({ url: '/contact_received.php', type: "GET", data: datastring, cache: false, success: function (html) { $('#formdiv').fadeOut('slow',complete); function complete() { $('#formdiv').fadeIn('slow').html(html); $('.loading').hide(); } } }); } }); form code is here:
Your Name Your Email messsage
This doesn't break the validation, but it just takes me right through to the contact_received.php page. What am I doing wrong?
to be clear, the validation is working fine everything is good except I don't want it to submit. SHould I remove the "action" from the form?

以上就是How to change a form's containing div after validation & submission?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准