通知系统无法正常工作JSON/PHP
我正试图用未读通知的数量来敲响通知铃。我在php的帮助下使用Javascript从mysqli表中获取数据并将其作为JSON类型返回,但我不知道问题出在哪里,我没有收到任何输出 这里唯一有效的是,当我点击钟形图标时,它将我的评论状态从0更改为1 谢谢大家! 这是我的密码: Javascript:通知系统无法正常工作JSON/PHP,php,mysql,json,ajax,notifications,Php,Mysql,Json,Ajax,Notifications,我正试图用未读通知的数量来敲响通知铃。我在php的帮助下使用Javascript从mysqli表中获取数据并将其作为JSON类型返回,但我不知道问题出在哪里,我没有收到任何输出 这里唯一有效的是,当我点击钟形图标时,它将我的评论状态从0更改为1 谢谢大家! 这是我的密码: Javascript: $(document).ready(function(){ function load_unseen_notification(view = '') { $.ajax({ url:".
$(document).ready(function(){
function load_unseen_notification(view = '')
{
$.ajax({
url:"./include/fetch_messages.php",
method:"POST",
data:{view:view},
dataType: "json",
success:function(data)
{
$('.dropdown-menu').html(data.notification);
if(data.unseen_notification > 0)
{
$('.count').html(data["unseen_notification"]);
}
}
});
}
load_unseen_notification();
$(document).on('click', '.dropdown-toggle', function(){
$('.count').html('');
load_unseen_notification('yes');
});
});
我的fetch_messages.php文件:
<?php include 'connect.php'; ?>
<?php
//fetch_messages.php;
if(isset($_POST["view"]))
{
echo "string";
if($_POST["view"] != '')
{
$update_query = "UPDATE comments SET comment_status=1 WHERE comment_status=0";
mysqli_query($conn, $update_query);
}
$query = "SELECT * FROM comments ORDER BY id DESC LIMIT 5";
$result = mysqli_query($conn, $query);
$output = '';
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
$output .= '
<li>
<a href="#">
<strong>'.$row["user_commented"].'</strong><br />
<small><em>'.$row["comment"].'</em></small>
</a>
</li>
<li class="divider"></li>
';
}
}
else
{
$output .= '<li><a href="#" class="text-bold text-italic">No Notification Found</a></li>';
}
$query_1 = "SELECT * FROM comments WHERE comment_status=1";
$result_1 = mysqli_query($conn, $query_1);
$count = mysqli_num_rows($result_1);
$data = array(
'notification' => $output,
'unseen_notification' => $count
);
echo json_encode($data);
}
?>
我的html,其中是我的输出:
<ul >
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="label label-pill label-danger count" style="border-radius:10px;"></span> <span class="glyphicon glyphicon-envelope" style="font-size:18px;"></span></a>
<ul class="dropdown-menu">...</ul>
</li>
</ul>
-
…
我找到了它,我有一行“echo‘string’”;“我把它取下来,现在一切都好了!谢谢你的指导 显示您在ajax calli-put-console.log(数据)上获得的内容;在success function but nothing中,然后使用浏览器开发工具的网络面板检查请求得到的响应。另外,请阅读在这样的环境中调试的基础知识-因此不是反复解释的地方。也许我发现了错误:“SyntaxError:JSON中位于位置0的意外标记s”,但我如何修复它?