通知系统工作不正常json/php

mmvthczy  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(304)

我正在努力使通知铃与未读通知计数。我在php的帮助下使用javascript从mysqli表中获取数据并将其作为json类型返回,但是我不知道问题出在哪里,我没有收到任何输出。
这里唯一有效的是,当我点击铃声图标时,它将我的评论状态从0更改为1。
谢谢您!
这是我的密码:
javascript代码:

$(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\u 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>
ezykj2lf

ezykj2lf1#

我找到了,我有一行“echo‘string’;”我把它取下来,现在一切都好了!谢谢你的指导!

相关问题