实现网站实时通信
· 四种方式,第二三四种方式需要服务器端做操作的
-
写计时器进行Ajax轮询
// 每秒调用一次http请求 setInterval(function () { var xhr = new XMLHttpRequest(); xhr.open('POST', 'url', true); xhr.setRequestHeader('Content-Type', 'application/json'); xhr.send(); xhr.onreadystatechange = function () { if (xhr.readyState == 4 && xhr.status == 200) { console.log