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

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

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

  1. $(document).ready(function(){
  2. function load_unseen_notification(view = '')
  3. {
  4. $.ajax({
  5. url:"./include/fetch_messages.php",
  6. method:"POST",
  7. data:{view:view},
  8. dataType: "json",
  9. success:function(data)
  10. {
  11. $('.dropdown-menu').html(data.notification);
  12. if(data.unseen_notification > 0)
  13. {
  14. $('.count').html(data["unseen_notification"]);
  15. }
  16. }
  17. });
  18. }
  19. load_unseen_notification();
  20. $(document).on('click', '.dropdown-toggle', function(){
  21. $('.count').html('');
  22. load_unseen_notification('yes');
  23. });
  24. });

我的fetch\u messages.php文件:

  1. <?php include 'connect.php'; ?>
  2. <?php
  3. //fetch_messages.php;
  4. if(isset($_POST["view"]))
  5. {
  6. echo "string";
  7. if($_POST["view"] != '')
  8. {
  9. $update_query = "UPDATE comments SET comment_status=1 WHERE comment_status=0";
  10. mysqli_query($conn, $update_query);
  11. }
  12. $query = "SELECT * FROM comments ORDER BY id DESC LIMIT 5";
  13. $result = mysqli_query($conn, $query);
  14. $output = '';
  15. if(mysqli_num_rows($result) > 0)
  16. {
  17. while($row = mysqli_fetch_array($result))
  18. {
  19. $output .= '
  20. <li>
  21. <a href="#">
  22. <strong>'.$row["user_commented"].'</strong><br />
  23. <small><em>'.$row["comment"].'</em></small>
  24. </a>
  25. </li>
  26. <li class="divider"></li>
  27. ';
  28. }
  29. }
  30. else
  31. {
  32. $output .= '<li><a href="#" class="text-bold text-italic">No Notification Found</a></li>';
  33. }
  34. $query_1 = "SELECT * FROM comments WHERE comment_status=1";
  35. $result_1 = mysqli_query($conn, $query_1);
  36. $count = mysqli_num_rows($result_1);
  37. $data = array(
  38. 'notification' => $output,
  39. 'unseen_notification' => $count
  40. );
  41. echo json_encode($data);
  42. }
  43. ?>

我的html输出将是:

  1. <ul >
  2. <li class="dropdown">
  3. <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>
  4. <ul class="dropdown-menu">...</ul>
  5. </li>
  6. </ul>
ezykj2lf

ezykj2lf1#

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

相关问题