douxun2023 2010-07-15 10:18
浏览 154
已采纳

在网页上显示进程日志

I've got a web page that allows to start a certain process and then redirects to another page that displays log file of that process. Since execution takes up to 10 minutes, I want log page to autoupdate itself or load data from the file periodically.

Right now I added

<meta http-equiv="refresh" content="5;url=log.php#bottom" /> 

to html/head but wondering if there may be a better solution. Can someone give any advice on aproaching this problem?

  • 写回答

4条回答 默认 最新

  • douwen5690 2010-07-15 10:49
    关注

    I do it this way:

    var current_length = 0;
    function update() {
      setTimeout(update, 3000);
      $.post("/update_url", { 'current_length': current_length }, function(data) {
        if (data.current_length != current_length) return; //it's too old answer
        $("#log").html($("#log").html() + data.text);
        current_length += data.text.length;
      }, "json"); 
    }
    update();
    

    The server must skip several bytes at beginning and send json with current_length and the rest of file.

    I prefer using memcached to store process output.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?