var request = false;
//------------------判断浏览器并建立对象----------------------------------------------------------------
try {//尝试创建 XMLHttpRequest 对象
request = new XMLHttpRequest();//---此对象将兼容除IE外大部分浏览器!
}//-
catch (trymicrosoft) {//如果失败 catch (trymicrosoft)
try {//尝试使用较新版IE兼容的对象(Msxml2.XMLHTTP)
request = new ActiveXObject("Msxml2.XMLHTTP");//---此对象将兼容老版本IE
}//-
catch (othermicrosoft) {//如果失败 catch (othermicrosoft)
try {//尝试使用较老版IE兼容的对象(Microsoft.XMLHTTP)
request = new ActiveXObject("Microsoft.XMLHTTP");//---此对象将兼容新版本IE
}//-
catch (failed) {//如果失败 catch (failed)
request = false;//request = false
alert("Object Error!");
}
}
}
defaultPages();
//-------------------------------------------------------------------------------------------------------------*/
//**********读取数据***********************************************************
function defaultPages() {
var url = "Demo.asp";
request.open("GET", url, true);//open方法 ("方式",url,是否异步)
request.onreadystatechange = updatePage;//判断服务器处理的结果
request.send(null);//送出.
}
function selectPages(Method,Pages) {
//先删除以前的数据
for(i=0;i<3;i++)
document.getElementById("MyTable").deleteRow();
//----------------
if (Method == "Previous"){
var PageTemp = document.getElementById("PageNow").value;
var PageNow = parseInt(PageTemp)-1;
//alert (PageNow);//debug
var url = "Demo.asp?Page="+PageNow;
request.open("GET", url, true);
request.onreadystatechange = updatePage;
request.send(null);
}
else if (Method == "Next"){
var PageTemp = document.getElementById("PageNow").value;
var PageNow = parseInt(PageTemp)+1;
//alert (PageNow);//debug
var url = "Demo.asp?Page="+PageNow;
request.open("GET", url, true);
request.onreadystatechange = updatePage;
request.send(null);
}
}
//***********服务器是否处理完成.**********************************************************************************
function updatePage() {
if (request.readyState <= 3){//小于或等于状态3----loading.
document.getElementById("Status").innerHTML = "Loading...";
document.getElementById("Pages").innerHTML = "Previous│Next";
}
if (request.readyState == 4){//状态4----完成.
if (request.status == 200) {//如果http状态为200--当成功获取获取数据.
requestAllright();
}else{//如果http状态为404--http报错.
document.getElementById("Status").innerHTML = "Error:" + request.status;
document.getElementById("Pages").innerHTML = "Previous│Next";
}
}
}
//***********处理完成-生成数据.**********************************************************************************
function requestAllright() {
var getStr = request.responseText;
var getValue = getStr.split(",");
var PageCount = getValue[0];
var PageNow = getValue[1];
var Contact = [
[getValue[2],getValue[3],getValue[4],getValue[5]],
[getValue[6],getValue[7],getValue[8],getValue[9]],
[getValue[10],getValue[11],getValue[12],getValue[13]]
];
for (var List=0;List<Contact.length;List++){
var MyTr = MyTable.insertRow();//创建Tr标签
for (var Cell=0;Cell<Contact[List].length;Cell++){//Td循环
var MyTd = MyTr.insertCell();//创建Td标签
MyTd.innerHTML = Contact[List][Cell];//给Td标签插入内容
if (Cell == 0)//如果当前为每行的第一个Td
MyTd.id = "Number";//赋予其ID为Number
}
}
//上一页下一页处的判断,是否可以点击******************************************************************************************
if (PageNow == PageCount){
document.getElementById("Pages").innerHTML = "<a href=javascript:selectPages('Previous','0'); target=_self class=pagesTag>Previous</a>│Next"
}
else if (PageNow == 1){
document.getElementById("Pages").innerHTML = "Previous│<a href=javascript:selectPages('Next','0'); target=_self class=pagesTag>Next</a>"
}
else if (PageNow != 1 || PageNow != PageCount){
document.getElementById("Pages").innerHTML = "<a href=javascript:selectPages('Previous','0'); target=_self class=pagesTag>Previous</a>│<a href=javascript:selectPages('Next','0'); target=_self class=pagesTag>Next</a>"
}
//上一页下一页处的判断,是否可以点击******************************************************************************************
document.getElementById("PageCount").value = PageCount;
document.getElementById("PageNow").value = PageNow;
document.getElementById("Status").innerHTML = "Done with!";
//alert(PageCount);//debug
//alert(PageNow);//debug
}
新闻热点
疑难解答
图片精选