php 服务器推送问题。
现在准备做个聊天的功能,在网上看了下,说用 推技术啊。
但是不懂。用ajax 轮询的话 效率很低啊。。。
[解决办法]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body><div id="test"></div><script type="text/javascript">function test(){ var aj; try{aj=new ActiveXObject("Msxml2.XMLHTTP");} catch(e){ try{aj=new ActiveXObject("Microsoft.XMLHTTP");} catch(E){aj=false;} } var time = Math.round(new Date().getTime() / 1000); if(!aj&&typeof XMLHttpRequest!=undefined)aj=new XMLHttpRequest(); aj.open("GET","b.php?time="+time,true); aj.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=utf-8'); aj.onreadystatechange=function(){ if(aj.readyState==4&&aj.status==200){ document.getElementById("test").innerHTML += aj.responseText; test(); // 收到结果后重新建立连接 } } aj.send(null);}test();</script></body></html>