-1

在继续阅读之前,我想要实现的是在不刷新 div 的情况下自动更新 div 内的内容。(有点像 Facebook 聊天,添加新消息时我看不到聊天闪烁或闪烁,而是无缝添加新数据。)

在我的索引中,我有以下标记:

<div>   
  <?php
    if($_SESSION['Login']==1){
      include_once('Branch_Pages/Bar_in.php');
      }
    else{
      include_once('Branch_Pages/Bar_out.php');
      }
  ?>
</div>

会话变量登录设置为“1”当用户登录时,在 Bar_in.php 中我有一个搜索框,它根据 php 生成的数据列表提供建议。

<datalist  id="StudentList">
  <?php
    for($x=0;$x<$_SESSION['num_rows'];$x++){
        echo'
                <option value="'.$Enroll_F_name[$x].' '.$Enroll_L_name[$x].'" data-id="'.$enroll_data_No[$x].'" label="'.$_SESSION['Enroll_Index_num'][$x].'">
        ';
    }
  ?>
</datalist>

如何在不刷新 div 的情况下自动更新数据列表(因为刷新会使 Bar 闪烁)或在刷新时不使其闪烁?

4

1 回答 1

1

You may have a lot to learn here.

  1. After your page loads, start polling the server for new data, this basically means firing a request every few seconds (5,10,15,30, whatever makes sense for your app) Here is some info on polling
  2. That request should return the data you need, preferably in a JSON object, or some other format that is easy for you to parse with javascript.
  3. Turn the JSON data into dom objects representing what is being repeated in your datalist
  4. use jQuery to append the objects to the datalist children array
于 2013-03-18T21:29:20.337 回答