PHP+Ajax实时自动检测是否联网-bbs.it-home.org </li> <li><!-- <li>var xmlHttp; <li>function createXMLHttpRequest(){ <li> if(window.ActiveXObject){ <li> xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); <li> } <li> else if(window.XMLHttpRequest){ <li> xmlHttp = new XMLHttpRequest(); <li> } <li>} <li>function start(){ <li> createXMLHttpRequest(); <li> var url="getNetLink"; <li> xmlHttp.open("GET",url,true); <li> xmlHttp.onreadystatechange = callback; <li> xmlHttp.send(null); <li>} <li>function callback(){ <li> if(xmlHttp.readyState == 4){ <li> if(xmlHttp.status == 200){ <li> document.getElementById("shownetlink").innerHTML = xmlHttp.responseText; <li> setTimeout("start()",8000); <li> } <li> } <li>} <li>// --> </li> <li> PHP+Ajax实时自动检测是否联网 当前网络状态: 复制代码 2,php代码 //检测网络连接,是否已联网public function getNetLink(){ header("cache-control:no-cache,must-revalidate"); header("Content-Type:text/html;charset=utf-8"); $file=fopen("http://bbs.it-home.org/", "r"); if (!$file){ $shownetlink = "网络连接失败"; }else{ $shownetlink = "网络连接正常"; } echo $shownetlink; } 复制代码