Javascript 不同页面上的ajax评论系统
我一直在玩webcodo评论系统: DB表:“评论” 我已经将id_post(应该包含页面id)从int(11)更改为varchar(32),因为我使用的页面id不仅仅由数字组成 文件:index.phpJavascript 不同页面上的ajax评论系统,javascript,php,jquery,mysql,ajax,Javascript,Php,Jquery,Mysql,Ajax,我一直在玩webcodo评论系统: DB表:“评论” 我已经将id_post(应该包含页面id)从int(11)更改为varchar(32),因为我使用的页面id不仅仅由数字组成 文件:index.php <?php // Connect to the database include('config.php'); $id_post = "1"; //the post or the page id ?> <div class="cmt-container" >
<?php
// Connect to the database
include('config.php');
$id_post = "1"; //the post or the page id
?>
<div class="cmt-container" >
<?php
$sql = mysql_query("SELECT * FROM comments WHERE id_post = '$id_post'") or die(mysql_error());;
while($affcom = mysql_fetch_assoc($sql)){
$name = $affcom['name'];
$email = $affcom['email'];
$comment = $affcom['comment'];
$date = $affcom['date'];
?>
<div class="cmt-cnt">
<div class="thecom">
<h5><?php echo $name; ?></h5><span data-utime="1371248446" class="com-dt"><?php echo $date; ?></span>
<br/>
<p>
<?php echo $comment; ?>
</p>
</div>
</div><!-- end "cmt-cnt" -->
<?php } ?>
<div class="new-com-bt">
<span>Write a comment ...</span>
</div>
<div class="new-com-cnt">
<input type="text" id="name-com" name="name-com" value="" placeholder="Your name" />
<input type="text" id="mail-com" name="mail-com" value="" placeholder="Your e-mail adress" />
<textarea class="the-new-com"></textarea>
<div class="bt-add-com">Post comment</div>
<div class="bt-cancel-com">Cancel</div>
</div>
<div class="clear"></div>
</div><!-- end of comments container "cmt-container" -->
<script type="text/javascript">
$(function(){
//alert(event.timeStamp);
$('.new-com-bt').click(function(event){
$(this).hide();
$('.new-com-cnt').show();
$('#name-com').focus();
});
/* when start writing the comment activate the "add" button */
$('.the-new-com').bind('input propertychange', function() {
$(".bt-add-com").css({opacity:0.6});
var checklength = $(this).val().length;
if(checklength){ $(".bt-add-com").css({opacity:1}); }
});
/* on clic on the cancel button */
$('.bt-cancel-com').click(function(){
$('.the-new-com').val('');
$('.new-com-cnt').fadeOut('fast', function(){
$('.new-com-bt').fadeIn('fast');
});
});
// on post comment click
$('.bt-add-com').click(function(){
var theCom = $('.the-new-com');
var theName = $('#name-com');
var theMail = $('#mail-com');
if( !theCom.val()){
alert('You need to write a comment!');
}else{
$.ajax({
type: "POST",
url: "ajax/add-comment.php",
data: 'act=add-com&id_post='+<?php echo $id_post; ?>+'&name='+theName.val()+'&email='+theMail.val()+'&comment='+theCom.val(),
success: function(html){
theCom.val('');
theMail.val('');
theName.val('');
$('.new-com-cnt').hide('fast', function(){
$('.new-com-bt').show('fast');
$('.new-com-bt').before(html);
})
}
});
}
});
});
</script>
因此,在变量中添加只包含数字字符的注释就可以了。我希望有人能帮我解决这个问题。问题出在javascript中:
data: 'act=add-com&id_post='+<?php echo $id_post; ?>+'&name='+theName.val()+'&email='+theMail.val()+'&comment='+theCom.val(),
data:'act=add com&id_post='++'&name='+theName.val()+'&email='+theMail.val()+'&comment='+theCom.val(),
应已输出:
data: 'act=add-com&id_post=+<?php echo $id_post; ?>+&name='+theName.val()+'&email='+theMail.val()+'&comment='+theCom.val(),
data:'act=add com&id\u post=++&name='+theName.val()+'&email='+theMail.val()+'&comment='+theCom.val(),
如果没有“”id\u post和id是否存储相同的值?是否有任何错误?你确定你把它改成了varchar(32)…?id_post用于页面id,id用于海报id。当它们具有相同的值时,会导致问题吗?id包含数字(1,2,3,4等),id_post包含(1,1,1,1)。我确信它已更改为varchar,因为我可以手动插入文本值。表名为comment或comments???表名为comments
data: 'act=add-com&id_post='+<?php echo $id_post; ?>+'&name='+theName.val()+'&email='+theMail.val()+'&comment='+theCom.val(),
data: 'act=add-com&id_post=+<?php echo $id_post; ?>+&name='+theName.val()+'&email='+theMail.val()+'&comment='+theCom.val(),