注:1.手动删除ie临时文件后可以获取新数据;2.刷新页面不能获取新数据;3.不要说加随机数在url上,我不知道具体加在哪里,我乱试了也还是不行;4.希望得到的效果是点击“获取数据”后可以显示xml里的最新数据;5.正在赶毕业设计,时间紧迫,请高人指点!
<script type="text/javascript">
//设一个变量 var XMLHttpReq=false;
//创建一个XMLHttpRequest对象
function createXMLHttpRequest(){
if(window.XMLHttpRequest){ //Mozilla
XMLHttpReq=new XMLHttpRequest();
}
else if(window.ActiveXObject){
try{
XMLHttpReq=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
XMLHttpReq=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){}
}
}
}
//发送请求函数
function send(url){
createXMLHttpRequest();
XMLHttpReq.open("GET",url,true);
XMLHttpReq.onreadystatechange=proce; //指定响应的函数
XMLHttpReq.send(null); //发送请求
}
function proce(){
if(XMLHttpReq.readyState==4){ //对象状态
if(XMLHttpReq.status==200){//信息已成功返回,开始处理信息
alert("window_onload````");
windows_onload();//调用显示xml的函数
}else{
window.alert("所请求的页面有异常");
}
}
} var intRecordPerPage;
//每页记录数
intRecordPerPage = 7;
function windows_onload()
{
var vis=document.getElementById("DisplayArea");
vis.style.display="";//显示
vis.innerHTML="";
var max = parseInt(intRecordPerPage,10) + 1;
Style.XMLDocument.selectNodes("//xsl:for-each/@select")(1).value = "./*[position()<" +max + " and position()>0]";
Style.XMLDocument.selectNodes("//@onclick")(1).value="previousPage(1)";
Style.XMLDocument.selectNodes("//@onclick")(2).value="nextPage(1)";
transform();
setPageCount(); }
function transform()
{
DisplayArea.innerHTML = Data.XMLDocument.transformNode(Style.XMLDocument);
RecordPerPage.Value = intRecordPerPage;
}
function redisplay(intPage)
{
var strDisplay,intPageCount,intRecordCount
intPageCount = PageCount.innerHTML;
intRecordCount = RecordCount.innerHTML;
transform()
PageCount.innerHTML = intPageCount;
RecordCount.innerHTML = intRecordCount;
CurrentPage.innerHTML = intPage;
}
function hiddenDiv(){
var hid=document.getElementById("DisplayArea");
hid.innerHTML="";
hid.style.display="none";//隐藏
}
function Sort(varField)
{
var sortField,sortOrderAttribute;
sortField = Style.XMLDocument.selectSingleNode("//xsl:sort/@select");
sortOrderAttribute = Style.XMLDocument.selectSingleNode("//xsl:sort/@order");
if(sortField.value==varField)
{
if(sortOrderAttribute.value=="descending")
{
sortOrderAttribute.value = "ascending";
}
else
{
sortOrderAttribute.value="descending"
}
}
else
{
sortField.value = varField;
sortOrderAttribute.value = "ascending";
}
sortField = null;
sortOrderAttribute = null; redisplay(CurrentPage.innerHTML);
}
function setPageCount()
{
PageCount.innerHTML = getNumberOfPages();
CurrentPage.innerHTML = 1
}
function getNumberOfPages(intTotalRecords)
{
var intPages;
intTotalRecords = Data.XMLDocument.selectNodes("/*/*").length;
RecordCount.innerHTML =intTotalRecords;
if(intTotalRecords%intRecordPerPage==0)
{
intPages = parseInt(intTotalRecords/intRecordPerPage,10);
}
else
{
intPages = parseInt(intTotalRecords/intRecordPerPage,10) + 1;
}
return intPages;
}
function setRecordPerPage()
{
if(!isNaN(RecordPerPage.value))
{
intRecordPerPage = RecordPerPage.value;
window_onload();
}
else
{
alert("Illegle input!");
RecordPerPage.value="";
}
}
function nextPage(intPage)
{
var max,min;
max = intPage*intRecordPerPage;
if(max<Data.selectNodes("/*/*").length)
{
intPage = intPage - 1 + 2;
Style.XMLDocument.selectNodes("//@onclick")(1).value="previousPage("+intPage+")";
Style.XMLDocument.selectNodes("//@onclick")(2).value="nextPage("+intPage+")";
max = intPage*intRecordPerPage;
min = (intPage-1)*intRecordPerPage;
Style.XMLDocument.selectNodes("//xsl:for-each/@select")(1).value="./*[position()<=" + max + " and position()>" + min + "]";
redisplay(intPage);
}
}
function previousPage(intPage)
{
if(intPage>1)
{
var max,min;
intPage = intPage - 1;
Style.XMLDocument.selectNodes("//@onclick")(1).value="previousPage("+intPage+")";
Style.XMLDocument.selectNodes("//@onclick")(2).value="nextPage("+intPage+")";
max = intPage*intRecordPerPage;
min = (intPage-1)*intRecordPerPage;
Style.XMLDocument.selectNodes("//xsl:for-each/@select")(1).value="./*[position()<=" + max + " and position()>" + min + "]";
redisplay(intPage);
}
}
function FirstPage()
{
var max = parseInt(intRecordPerPage,10) + 1;
Style.XMLDocument.selectNodes("//@onclick")(1).value="previousPage(1)";
Style.XMLDocument.selectNodes("//@onclick")(2).value="nextPage(1)";
Style.XMLDocument.selectNodes("//xsl:for-each/@select")(1).value="./*[position()<" + max + " and position()>0]";
transform();
setPageCount();
}
function LastPage()
{
var intTotalPages;
intTotalPages = getNumberOfPages();
nextPage(intTotalPages-1);
}
</script>
</head>
<body> <p align="center" style="font-weight:bold;font-size:12pt;color:#0000FF;border-bottom:3px double red;padding-bottom:5px">
<input type="button" value="获取上传列表" onclick="send('showrecords.jsp?r='+Math.random());"/>
<input type="button" value="隐藏上传列表" onclick="hiddenDiv();"/>
</p>
<xml id="Data" src="list.xml"></xml><!--设置要显示的xml-->
<xml id="Style" src="orders.xsl"></xml><div id="DisplayArea"></div>
<script type="text/javascript">
//设一个变量 var XMLHttpReq=false;
//创建一个XMLHttpRequest对象
function createXMLHttpRequest(){
if(window.XMLHttpRequest){ //Mozilla
XMLHttpReq=new XMLHttpRequest();
}
else if(window.ActiveXObject){
try{
XMLHttpReq=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
XMLHttpReq=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){}
}
}
}
//发送请求函数
function send(url){
createXMLHttpRequest();
XMLHttpReq.open("GET",url,true);
XMLHttpReq.onreadystatechange=proce; //指定响应的函数
XMLHttpReq.send(null); //发送请求
}
function proce(){
if(XMLHttpReq.readyState==4){ //对象状态
if(XMLHttpReq.status==200){//信息已成功返回,开始处理信息
alert("window_onload````");
windows_onload();//调用显示xml的函数
}else{
window.alert("所请求的页面有异常");
}
}
} var intRecordPerPage;
//每页记录数
intRecordPerPage = 7;
function windows_onload()
{
var vis=document.getElementById("DisplayArea");
vis.style.display="";//显示
vis.innerHTML="";
var max = parseInt(intRecordPerPage,10) + 1;
Style.XMLDocument.selectNodes("//xsl:for-each/@select")(1).value = "./*[position()<" +max + " and position()>0]";
Style.XMLDocument.selectNodes("//@onclick")(1).value="previousPage(1)";
Style.XMLDocument.selectNodes("//@onclick")(2).value="nextPage(1)";
transform();
setPageCount(); }
function transform()
{
DisplayArea.innerHTML = Data.XMLDocument.transformNode(Style.XMLDocument);
RecordPerPage.Value = intRecordPerPage;
}
function redisplay(intPage)
{
var strDisplay,intPageCount,intRecordCount
intPageCount = PageCount.innerHTML;
intRecordCount = RecordCount.innerHTML;
transform()
PageCount.innerHTML = intPageCount;
RecordCount.innerHTML = intRecordCount;
CurrentPage.innerHTML = intPage;
}
function hiddenDiv(){
var hid=document.getElementById("DisplayArea");
hid.innerHTML="";
hid.style.display="none";//隐藏
}
function Sort(varField)
{
var sortField,sortOrderAttribute;
sortField = Style.XMLDocument.selectSingleNode("//xsl:sort/@select");
sortOrderAttribute = Style.XMLDocument.selectSingleNode("//xsl:sort/@order");
if(sortField.value==varField)
{
if(sortOrderAttribute.value=="descending")
{
sortOrderAttribute.value = "ascending";
}
else
{
sortOrderAttribute.value="descending"
}
}
else
{
sortField.value = varField;
sortOrderAttribute.value = "ascending";
}
sortField = null;
sortOrderAttribute = null; redisplay(CurrentPage.innerHTML);
}
function setPageCount()
{
PageCount.innerHTML = getNumberOfPages();
CurrentPage.innerHTML = 1
}
function getNumberOfPages(intTotalRecords)
{
var intPages;
intTotalRecords = Data.XMLDocument.selectNodes("/*/*").length;
RecordCount.innerHTML =intTotalRecords;
if(intTotalRecords%intRecordPerPage==0)
{
intPages = parseInt(intTotalRecords/intRecordPerPage,10);
}
else
{
intPages = parseInt(intTotalRecords/intRecordPerPage,10) + 1;
}
return intPages;
}
function setRecordPerPage()
{
if(!isNaN(RecordPerPage.value))
{
intRecordPerPage = RecordPerPage.value;
window_onload();
}
else
{
alert("Illegle input!");
RecordPerPage.value="";
}
}
function nextPage(intPage)
{
var max,min;
max = intPage*intRecordPerPage;
if(max<Data.selectNodes("/*/*").length)
{
intPage = intPage - 1 + 2;
Style.XMLDocument.selectNodes("//@onclick")(1).value="previousPage("+intPage+")";
Style.XMLDocument.selectNodes("//@onclick")(2).value="nextPage("+intPage+")";
max = intPage*intRecordPerPage;
min = (intPage-1)*intRecordPerPage;
Style.XMLDocument.selectNodes("//xsl:for-each/@select")(1).value="./*[position()<=" + max + " and position()>" + min + "]";
redisplay(intPage);
}
}
function previousPage(intPage)
{
if(intPage>1)
{
var max,min;
intPage = intPage - 1;
Style.XMLDocument.selectNodes("//@onclick")(1).value="previousPage("+intPage+")";
Style.XMLDocument.selectNodes("//@onclick")(2).value="nextPage("+intPage+")";
max = intPage*intRecordPerPage;
min = (intPage-1)*intRecordPerPage;
Style.XMLDocument.selectNodes("//xsl:for-each/@select")(1).value="./*[position()<=" + max + " and position()>" + min + "]";
redisplay(intPage);
}
}
function FirstPage()
{
var max = parseInt(intRecordPerPage,10) + 1;
Style.XMLDocument.selectNodes("//@onclick")(1).value="previousPage(1)";
Style.XMLDocument.selectNodes("//@onclick")(2).value="nextPage(1)";
Style.XMLDocument.selectNodes("//xsl:for-each/@select")(1).value="./*[position()<" + max + " and position()>0]";
transform();
setPageCount();
}
function LastPage()
{
var intTotalPages;
intTotalPages = getNumberOfPages();
nextPage(intTotalPages-1);
}
</script>
</head>
<body> <p align="center" style="font-weight:bold;font-size:12pt;color:#0000FF;border-bottom:3px double red;padding-bottom:5px">
<input type="button" value="获取上传列表" onclick="send('showrecords.jsp?r='+Math.random());"/>
<input type="button" value="隐藏上传列表" onclick="hiddenDiv();"/>
</p>
<xml id="Data" src="list.xml"></xml><!--设置要显示的xml-->
<xml id="Style" src="orders.xsl"></xml><div id="DisplayArea"></div>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货