1. 程式人生 > >html通過js呼叫php實現區域性更新

html通過js呼叫php實現區域性更新

var xmlHttp; function createXMLHttpRequest(){ if(window.ActiveXObject){ xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } else if(window.XMLHttpRequest){ xmlHttp = new XMLHttpRequest(); } } function start(){ createXMLHttpRequest(); var
url="http://www.52300.com/yzydede/yhsetipmap.php"; xmlHttp.open("POST",url,true); xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlHttp.onreadystatechange = callback; xmlHttp.send("sip="+document.getElementById("sip").value); } function
callback(){
if(xmlHttp.readyState == 4){ if(xmlHttp.status == 200 && xmlHttp.responseText != ""){ if (xmlHttp.responseText.indexOf("127") >= 0) { var bodyObj=document.getElementById("ipmap_list"); if
(bodyObj==null) { alert("Body of Table not Exist!"); return; } var rowCount = bodyObj.rows.length; var cellCount = bodyObj.rows[0].cells.length; var newRow = bodyObj.insertRow(rowCount++); newRow.insertCell(0).innerHTML=rowCount - 1; newRow.insertCell(1).innerHTML=document.getElementById("sip").value; newRow.insertCell(2).innerHTML=xmlHttp.responseText; } else alert(xmlHttp.responseText); } } } function getyhip(){ createXMLHttpRequest(); var url="http://www.52300.com/yzydede/yhgetipmap.php"; xmlHttp.open("POST",url,true); xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlHttp.onreadystatechange = yhcallback; xmlHttp.send(""); } function yhcallback(){ if(xmlHttp.readyState == 4){ if(xmlHttp.status == 200 && xmlHttp.responseText != ""){ if (xmlHttp.responseText.indexOf(".") >= 0) { var bodyObj=document.getElementById("ipmap_list"); if(bodyObj==null) { alert("Body of Table not Exist!"); return; } var strall= new Array(); strall=xmlHttp.responseText.split("|"); for (i=0; i<strall.length ;i++ ) { var allip = new Array(); allip = strall[i].split("-"); var rowCount = bodyObj.rows.length; var cellCount = bodyObj.rows[0].cells.length; var newRow = bodyObj.insertRow(rowCount++); newRow.insertCell(0).innerHTML=rowCount - 1; for (j=0; j<allip.length; j++) newRow.insertCell(1+j).innerHTML=allip[j]; } } else alert(xmlHttp.responseText); } } }