我有这个posts.php它使用唯一的id来查看不同的内容。例如:posts.php?id=1
显示其中有1,ID的ID在我的表中的所有数据= 2 2,依此类推......返回的AJAX数据不正确
此ID是保持在每个页面上的PHP变种$post_id
并以发送在我的jQuery/JavaScript的这个PHP变量,我用:
<div id = "dummy_disp" style = "display: none;">
<?php echo htmlspecialchars($post_id); ?>
</div>
<div id = "real_commentsno"></div>
(我知道,不要做它最好的方式,但它的工作原理)
它连接到我的JS:
var commentid = document.getElementById("dummy_disp");
var commentidreal = commentid.textContent;
$.ajax ({
type:"GET",
url:"php/post_comments.php",
data:'comid='+commentidreal,
success: function(data){
$("#real_commentsno").html(data);
}
});
我有这个post_comments.php
地方有:
$cc_g_postid = htmlentities($_GET['comid']);
$cc_postid = mysqli_real_escape_string($con,$cc_g_postid);
$cc_sql = "SELECT * FROM comments WHERE postuniqueid = '$cc_postid' ";
$cc_result = mysqli_query($con,$cc_sql);
$cc_count = mysqli_num_rows($cc_result);
echo $cc_count;
当我尝试与所连接的URL VAR查看post_comments.php
旁边:?comid=1
页面显示2
这是正确的,因为在我的桌子后id=1
只有2条评论。但是,当我去我的posts.php
ajax显示0,而不是2.我试着看看控制台,没有错误。
有什么我错过或错过了吗?此外,post_comments.php
是在位于mypage/php/post_comments.php
而posts.php
位于mypage/posts.php
(我不知道这是否是必要的信息,但也许网址被卡住它还是什么?)
[你看过浏览器开发工具中的AJAX请求/响应了吗?你有没有在项目中包含jQuery库?是否有任何错误报告?你是在网络服务器上运行的吗?](http://jayblanchard.net/basics_of_jquery_ajax.html) –
'data:{comid:commentidreal}' – RiggsFolly