所有, 我有下面的代码后:提交表单与AJAX和地点的内容在DIV jQuery的验证
$(document).ready(function() {
$("#create_review").validate();
$("#submit_review_link").click(function() {
if ($("#create_review").valid()) {
$("#create_review").submit(function() { // catch the form's submit event
$.ajax({ // create an AJAX call...
data: $(this).serialize(), // get the form data
type: $(this).attr('method'), // GET or POST
url: $(this).attr('action'), // the file to call
success: function(response) { // on success..
alert("it is here");
$('#created').html(response); // update the DIV
}
});
return false; // cancel original event to prevent form submitting
});
}
return false;
});
});
下面是我实际的HTML表单:
<form action="save_review.php" method="post" name="create_review" id="create_review">
<textarea name="review" id="review" rows="5" class="required"></textarea>
</form>
<a class="button-2" href="#" id="submit_review_link" onClick="submit_form()">Submit Review</a>
我想验证这一点,然后在我创建的div中显示结果。它不工作,但我不知道为什么。任何想法将不胜感激。提前致谢。
你是什么意思“它不工作”?警报弹出吗? – Ivan 2011-12-31 17:11:04
Ctrl-Shift-J是你的朋友。 – ranksrejoined 2011-12-31 17:16:32
@伊万,这是正确的。警报不会弹出,没有任何东西进入div。在我的save_review.php文件中,我只是回声说“它工作”只是为了查看结果是否会填充div。这也没有发生。 – user1048676 2011-12-31 17:20:37