dtzh131555 2013-10-21 16:13
浏览 40

too long

This script is throwing this error every half second:

Uncaught InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable. signals.js:9
req.onreadystatechange signals.js:9
update_table signals.js:26
req.onreadystatechange

This is signals.js - I want it to reload every 5 seconds and if there is new content, to trigger the "Sound" alert.

    function update_table()
{

    var old_table = document.getElementById('signals').innerHTML;

    var req = new XMLHttpRequest();

    req.onreadystatechange = function(){
    if(req.status == 200)
    {
        if(req.readyState == 4)
        {
            var new_table = req.responseText;
            alert(old_table);
            alert(new_table);
            if(old_table != new_table)
            {
                //play sound
                alert("Sound!");
            }
            alert("Refresh!");
            setTimeout(update_table, 5000);
        }
        }
    }
    var link = "table.php?refresh=true";

    req.open("GET", link, false);
    req.send();

}
  • 写回答

2条回答 默认 最新

  • drvlf9739 2013-10-21 16:28
    关注

    First check if the req.readyState equals 4 and then check if the req.status equals 200. The HTTP status code isn't set before the request is processed, so you can't use it before the readyState equals 4.

    You can check this link for more info about the onreadystatechange event.

    评论

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计