【JS】长轮询

循环请求服务器数据

    function send () {
      xhr.open('GET', '/clock', true);
      xhr.onreadystatechange = function () {
        if (xhr.readyState === 4 && xhr.status === 200) {
          console.log(xhr.responseText);
          send()
        }
      }
      xhr.send()
    }
    send()

 

posted @ 2019-03-23 12:04  前端精髓  阅读(1455)  评论(0编辑  收藏  举报
在这里插入图片描述