我正在使用以下代码插入评论:
<div id="2" class="789678">
<div id="dynamic2">
<span class="error" style="display:none">Please Enter Valid Data</span>
<span class="success" style="display:none">Submitted Successfully</span>
<form action="http://localhost/ci/index.php/#"
method="post" accept-charset="utf-8" name="commentform" id="commentform">
<div style="display:none">
<input type="hidden" name="token" value="552e5dab8e50b8263c8b7ba548adaf5b">
</div>
<p>
<label for="Name">Name</label>
<br>
<input type="text" name="name" value="" id="name" size="30" placeholder="Please Enter Name or Nick name"
class="required">
</p>
<p>
<label for="email">Email Address</label>
<br>
<input type="text" name="email" value="" id="email" size="30" placeholder="Enter Email Address"
class="required">
</p>
<p>
<label for="comment">comment</label>
<br>
<textarea name="content" cols="40" rows="5" id="content" col="180" placeholder="Post Your Comment"
class="required"></textarea>
</p>
<input type="hidden" id="post_id" name="post_id" value="2">
<input type="hidden" id="num" name="num" value="789678">
<button name="button" type="reset" id="button" value="true">Add Comment</button>
</form>
</div>
<input type="button" id="adcom" value="Add Comment" style="display: none; ">
</div>
以下是我在不刷新页面的情况下提交页面的 jQuery 代码。它工作正常,但我需要添加无效的验证,并且它也没有显示任何错误:
<script>
$("#button").live("click", function (e) {
e.preventDefault();
$("#commentform").validate();
var currentId = $(this).parent().parent().parent().attr('id');
var num = $('#num').val();
var email = $('#email').val();
var post_id = $('#post_id').val();
var name = $('#name').val();
var content = $('#content').val();
var token = $('input[name="token"]').val();
var dataString = 'num=' + num + '&email=' + email + '&content_id=' + post_id + '&name=' + name + '&content=' + content + '&token=' + token;
$.ajax({
type: "POST",
url: "http://localhost/ci/index.php/mobiles/mobile_insert_comment/",
data: dataString,
success: function (result) {
$("#commentform").remove();
//$("#dynamic"+currentId).text(' successfully submitted');
$('.success').fadeIn(200).show();
$('.error').fadeOut(200).hide();
}
});
return false;
});
</script>
我正在使用以下 jQuery 验证插件:
<script type="text/javascript"
src="http://jzaefferer.github.com/jquery-validation/jquery.validate.js"></script>