Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 创建聊天窗口时,滚动条不会下降_Javascript_Php_Scrollbar_Chat - Fatal编程技术网

Javascript 创建聊天窗口时,滚动条不会下降

Javascript 创建聊天窗口时,滚动条不会下降,javascript,php,scrollbar,chat,Javascript,Php,Scrollbar,Chat,我目前正在开发一个聊天应用程序,它最多可以同时支持四个窗口 当我打开一个新的聊天窗口时,即使调用了该函数,滚动条也不会下降。无论何时我发送消息,它都可以正常工作 function createChat(caller_id) { $.ajax({ type: 'POST', url: 'create_chat_interface.php', data: { caller_id: caller_id, }

我目前正在开发一个聊天应用程序,它最多可以同时支持四个窗口

当我打开一个新的聊天窗口时,即使调用了该函数,滚动条也不会下降。无论何时我发送消息,它都可以正常工作

function createChat(caller_id) {
      $.ajax({
        type: 'POST',
        url: 'create_chat_interface.php',
        data: {
          caller_id: caller_id,
        },
        success: function(data) {
          if (!$('#chat-history-' + caller_id).length) {
            if ($.trim($("#chat1").html()) == '') {
              $('#chat1').html(data);
              document.getElementById("chat-close").id = 'chat-close1';
            } else if ($.trim($("#chat2").html()) == '') {
              $('#chat2').html(data);
              document.getElementById("chat-close").id = 'chat-close2';
            } else if ($.trim($("#chat3").html()) == '') {
              $('#chat3').html(data);
              document.getElementById("chat-close").id = 'chat-close3';
            } else if ($.trim($("#chat4").html()) == '') {
              $('#chat4').html(data);
              document.getElementById("chat-close").id = 'chat-close4';
            }
            $('#chat-input-' + caller_id).focus();
            scrollDown(caller_id);
          }
        }
      })
    }

scrollDowncaller\u id{$'chat-history-'+caller\u id.scrollTop$document.height*1000;}滚动函数:scrollDowncaller\u id{$'chat-history-'+caller\u id.scrollTop$document.height*1000;}
function fetch_chat_history($caller_id, $db)
{
  $query = "SELECT * FROM messages WHERE from_id = '$caller_id'
  OR to_id = '$caller_id' ORDER BY timestamp ASC";
  $result = mysqli_query($db, $query);
  $row = mysqli_fetch_assoc($result);

  $output = '<ul>';

  foreach ($result as $row) {
    if ($row['from_id'] == $caller_id) {
      $output .= '
      <li class="received"><p>' . $row['message'] . '</p></li>';
    } else {
      $output .= '
      <li class="sent"><p>' . $row['message'] . '</p></li>';
    }
  }

  $output .= '</ul>';

  return $output;
}