html test
<html><head>
<script type="text/javascript">
function showUser()
{
var FBee_cloud_rsp;
var IndexOfData;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
FBee_cloud_rsp = xmlhttp.responseText;
IndexOfData = FBee_cloud_rsp.indexOf("=")+1;
document.getElementById("txtHint").innerHTML=FBee_cloud_rsp.substring(IndexOfData);
if (FBee_cloud_rsp.substring(IndexOfData)==0)
{
document.getElementById("IMG").src="http://bbs.feibit.com/data/attachment/forum/201209/30/off.png";
}
else
{
document.getElementById("IMG").src="http://bbs.feibit.com/data/attachment/forum/201209/30/on.png";
}
}
}
xmlhttp.open("GET","get.php?userID=40&userKey=111111111111111&upDataCur",true);
xmlhttp.send();
//1秒钟刷新
window.setTimeout(showUser, 1000);
}
function sendCommand(cmdStr)
{
var FBee_cloud_rsp;
var IndexOfData;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
FBee_cloud_rsp = xmlhttp.responseText;
document.getElementById("ctRspStr").innerHTML=FBee_cloud_rsp;
}
}
xmlhttp.open("GET","ctput.php?userID=40&userKey=111111111111111&downData="+cmdStr,true);
xmlhttp.send();
}
</script>
</head>
<body>
<button type="button" onclick="showUser()">开始</button>
<div id="D">
<imgid="IMG"/>
<br />
</div>
<div id="txtHint"><b>data will be listed here.</b></div>
<button type="button1" onclick="sendCommand('CTO1%2001')">开灯</button>
<button type="button2" onclick="sendCommand('CTO1%2000')">关灯</button>
<div id="ctRspStr"><b>data will be listed here.</b></div>
</body>
</html>
页:
[1]