我有一个使用jquery进行验证的表单。表单的id是“contact”,它位于名为“formdiv”的div中。
我希望在提交时,不是将我带到一个新页面“contact_received.php”,而是用“contact_received.php”的内容替换“formdiv”的内容,包括提交的$_GET数据。(例如:echo'谢谢,'.$_GET['name'].'联系我们,我们会回复你关于'.$_GET['message']).我在网上寻找类似的东西,并想使用jquery提交处理程序:
$("#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();
}
}
});
}
});
<div id="formdiv">
<form id="contact" name="contact" action="/contact_received.php" method="get">
Your Name
<input type="text" name="name" id="name" value="" style="display:block;">
Your Email
<input type="text" name="email" value="" style="display:block;">
messsage
<textarea name="message" cols="50" rows="5" style="display:block;"></textarea>
<input type="submit" class="btn" value=
"Contact Us" name="Submit">
</form>
</div>
这并不会导致验证失败,但它直接将我带到了contact_received.php页面。我错在哪里了?