我正在将表单加载到页面和 div 中,如下所示:
<script type="text/javascript">
$('#comments').load('/pages/includes/comments.php', { user:"<?=$user?>", id:"<?=$id?>"
});
</script>
该页面加载正常,系统中的任何评论都显示,但是当我尝试添加新评论时它根本不起作用,下面的comments.php(如果我'包含'文件而不是ajax它可以正常工作顺便说一句):
require '/home/php_/lib/dbconnect.inc';
$comments_id = mysql_real_escape_string($_POST['comments_id']);
$comments = mysql_real_escape_string($_POST['comments']);
$id = mysql_real_escape_string($_POST['id']);
/*******************************************************/
/****************** add item
/*******************************************************/
if ($_POST[additem] == '1'){ // AA
$additem = mysql_query("
insert into comments (
id,
user_id,
comments
)
VALUES (
'$id',
'$user',
'$comments'
)",$db);
if(!$additem) { echo "input error ".mysql_error(); exit; } // debug
} // close AA
/*******************************************************/
/****************** end add item
/*******************************************************/
$coms = mysql_query("select * from comments where id = '$id';",$db);
if(!$coms) { echo "coms error ".mysql_error(); exit; } // debug
if (mysql_num_rows($coms)>0){ // 55
while($databack44 = mysql_fetch_array($coms)){ // 55
echo '<div style="width:100%; float:left;">'.$databack44[comments].'</div>';
}
} // 55
else {
echo 'No Comments';
}
?>
<form method="post" action="#">
<textarea name="comments"></textarea>
<input type="submit" value="Add" class="button green">
<input type="hidden" name="id" value="<?=$id?>">
<input type="hidden" name="additem" value="1">
</form>