由於模版頁比較長,這裡只登出AJAX代碼部分,即<Body>標籤前面的部分
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script type="text/javascript" language="javascript">
//建立適用用與多種瀏覽器的XMLHttpRequest對象的函數
function getXMLRequester( ){
var xmlhttp_request = false;
try{
if( window.ActiveXObject ){
for( var i = 5; i; i-- ){
try{
if( i == 2 ){xmlhttp_request=newActiveXObject("Microsoft.XMLHTTP");
}else{xmlhttp_request = new ActiveXObject( "Msxml2.XMLHTTP." + i + ".0");
xmlhttp_request.setRequestHeader("Content-Type","text/xml");xmlhttp_request.setRequestHeader("Content-Type","gb2312");
}
break;}
catch(e){
xmlhttp_request = false;
}
}
}else if( window.XMLHttpRequest ){
xmlhttp_request = new XMLHttpRequest();
if (xmlhttp_request.overrideMimeType) {
xmlhttp_request.overrideMimeType('text/xml');
}
}
}
catch(e){
xmlhttp_request = false;
}
return xmlhttp_request ;
}
function IDRequest() {
//定義收到伺服器的響應後需要執行的JavaScript函數
url='CheckLogin.aspx'//定義網址參數
//alert(url);
xmlhttp_request=getXMLRequester();//調用建立XMLHttpRequest的函數
xmlhttp_request.onreadystatechange = doContents;//調用doContents函數
xmlhttp_request.open('POST', url, true);
xmlhttp_request.send(null);
}
function doContents() {
if (xmlhttp_request.readyState == 4) {// 收到完整的伺服器響應
if (xmlhttp_request.status == 200) {//HTTP伺服器響應的值OK
var str = xmlhttp_request.responseText;//將伺服器返回的字串寫到頁面中ID為message的地區
if(str.length>583)
{
//self.location="../login.aspx";
location.href='../Login.aspx';
}
} else {
alert(http_request.status);
}
}
}
IDRequest();
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>$Chapter$-->>$Order$-->>$Title$</title>
<link href="../StyleSheet.css" rel="stylesheet" type="text/css" />
</head>