duanjiuhong5843 2009-10-17 20:36
浏览 11
已采纳

动态地向表中添加行

$(document).ready(function(){
var refreshId = setInterval(function() {
    periodicRefresh();
}, 9000);
})

.

function periodicRefresh()
{
    $.ajax({
        type: 'GET',
        url: 'include/ajaxActions.php',
        data: "action=displayLastEvent",

        success: function(msg){
            var newid = $(msg).attr("id");
                    current = $("#list tr:first").get(0).id;
                    if(newid != currentfirstrow){
                        $("#list").prepend(msg);
                lastrow = current-19;
                $('#'+lastrow).remove();
                    }
        }
    });
}

Here is an example of what the table row looks like:

<tr id="5094"  style="background:White;">
  <td class="tdstd">
  </td>
</tr>
  • 写回答

2条回答 默认 最新

  • doutan3040 2009-10-17 20:53
    关注

    That's a little hard to answer, without knowing how the XML that is returned from "ajaxActions.php" and your AJAX call is formatted. Also, I'm assuming that "currentfirstrow" is a global javascript variable accessible inside any function?

    function periodicRefresh()
    {
        $.ajax({
            type: 'GET',
            url: 'include/ajaxActions.php',
            data: "action=displayLastEvent",
    
            success: function(xml){
                var newfirstrow = $(xml).find("name_of_xml_node_that_contains_newly_returned_id").text();
                if(newfirstrow != currentfirstrow){
                    //do add new row()
                }
            },
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 slam rangenet++配置
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊