1、靜態文件123.html
<html>
<script type="text/javascript" src="showcontent.js"></script>
<body onload="ShowContent()">
<div id="content"></div>
</body>
</html>
<script type="text/javascript" src="showcontent.js"></script>
<body onload="ShowContent()">
<div id="content"></div>
</body>
</html>
2、JS文件showcontent.js
// JavaScript Document for set innerHTML
function setInnerHTML(objId, html){
try{
var obj = document.getElementById(objId);
obj.innerHTML = html;
}catch(exception){
alert("Make sure the object id is correct!");
}
}
function getInnerHTML(objId){
try{
var obj = document.getElementById(objId);
return obj.innerHTML;
}catch(exception){
alert("Make sure the object id is correct!");
}
}
/* Create a new XMLHttpRequest object to talk to the Web server */
var xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xmlHttp = false;
}
}
@end @*/
if (!xmlHttp && typeof XMLHttpRequest != "undefined") {
xmlHttp = new XMLHttpRequest();
}
function ShowContent(){
try{
var url = "showcontent.asp";
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = ContentOk;
xmlHttp.send(null);
}catch(exception){}
}
function ContentOk(){
if (xmlHttp.readyState == 4) {
try{
var response = xmlHttp.responseText;
var alertObj = document.getElementById("Content");
alertObj.innerHTML=response;
}catch(exception){}
}
}
function setInnerHTML(objId, html){
try{
var obj = document.getElementById(objId);
obj.innerHTML = html;
}catch(exception){
alert("Make sure the object id is correct!");
}
}
function getInnerHTML(objId){
try{
var obj = document.getElementById(objId);
return obj.innerHTML;
}catch(exception){
alert("Make sure the object id is correct!");
}
}
/* Create a new XMLHttpRequest object to talk to the Web server */
var xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xmlHttp = false;
}
}
@end @*/
if (!xmlHttp && typeof XMLHttpRequest != "undefined") {
xmlHttp = new XMLHttpRequest();
}
function ShowContent(){
try{
var url = "showcontent.asp";
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = ContentOk;
xmlHttp.send(null);
}catch(exception){}
}
function ContentOk(){
if (xmlHttp.readyState == 4) {
try{
var response = xmlHttp.responseText;
var alertObj = document.getElementById("Content");
alertObj.innerHTML=response;
}catch(exception){}
}
}
3、腳本文件showcontent.asp
<%
Response.Expires = -1
Response.ExpiresAbsolute = Now() - 1
Response.cachecontrol = "no-cache"
if session("id")="" then
str="請先登錄"
else
str="123456"
end if
Response.AddHeader "Content-Type","text/html; charset=gb2312"
Response.Write ""&str&""
%>
Response.Expires = -1
Response.ExpiresAbsolute = Now() - 1
Response.cachecontrol = "no-cache"
if session("id")="" then
str="請先登錄"
else
str="123456"
end if
Response.AddHeader "Content-Type","text/html; charset=gb2312"
Response.Write ""&str&""
%>