這是一款簡單的哦,我們先是建立ajax對象然後再發送給php檔案,最後傳回值,
<SCRIPT type="text/javascript">
<!--
var xmlHttp;
function creatXMLHttpRequest() {
if(window.ActiveXObject) {
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
} else if(window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}
function startRequest() {
var queryString;
var domain = "<?=$ip?>";
queryString = "q=" + domain;
creatXMLHttpRequest();
xmlHttp.open("POST","./?action=do","true");
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
xmlHttp.send(queryString);
}
function handleStateChange() {
if(xmlHttp.readyState == 1) {
document.getElementById('ipresult').style.cssText = "";
document.getElementById('ipresult').innerHTML = '<span class="green">結果載入中,請稍等...</span>';
}
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
document.getElementById('ipresult').style.cssText = "";
var allcon = xmlHttp.responseText;
document.getElementById('ipresult').innerHTML = allcon;
}
}
}
//-->
</SCRIPT>