【发布时间】:2018-04-13 07:04:23
【问题描述】:
我正在尝试创建一个页面,其中显示客户当前进行的聊天。 现在我使用 Openfire 作为服务器,使用 PHP Ajax 编写脚本。
Openfire 将数据转储到 MySQL 表中。 我使用 Codeigniter-PHP 检索所有记录:
public function get_chats()
{
$this->db->select('*');
$this->db->from('ofMessageArchive');
$query = $this->db->get();
$result = $query->result();
$this->data['messages'] = $result;
$this->data['subview'] = 'dashboard/test';
$this->load->view('_layout_main', $this->data);
}
现在在我看来我有桌子:
<table class="table table-striped table-bordered table-hover" >
<thead>
<th>From</th>
<th>To</th>
<th>Message</th>
<th>Time</th>
</thead>
<tbody>
<?php if(count($messages)): foreach($messages as $key => $message): ?>
<tr>
<td><?php $users = explode("__", $message->fromJID); echo $users[0];?></td>
<td><?php $tousers = explode("__", $message->toJID); echo $tousers[0]; ?></td>
<td><i class="material-icons">play_circle_filled</i>Message</td>
<td><?php echo $date->format('d-m-y H:i:s'); ?></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
现在我不想重新加载整个页面,而是每 5 秒刷新一次表格内容。
我正在使用 DataTables。
我还以为我可以将 json 传递给我的视图,但我不知道如何每 5 秒更新一次。
public function get_chats()
{
$this->db->select('*');
$this->db->from('ofMessageArchive');
$query = $this->db->get();
$result = $query->result();
if (count($result)) {
$response = json_encode($result);
}
else
{
$response = false;
}
echo $response;
}
这也将发送新的和旧的消息。 所以我只想将新闻消息附加到表格旧消息不应该重复
【问题讨论】:
-
它称为长池
标签: php jquery ajax codeigniter datatable