注:
1.手动删除ie临时文件后可以获取新数据;
2.刷新页面不能获取新数据;
3.不要说加随机数在url上,我不知道具体加在哪里,我乱试了也还是不行;
4.希望得到的效果是点击“获取数据”后可以显示xml里的最新数据;
5.正在赶毕业设计,时间紧迫,请高人指点!
<%@ page contentType="text/html" pageEncoding="gb2312" %>
<%@ page language="java" import="java.util.*,upload.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <title></title>
    <script type='text/javascript' src='dwr/interface/addxml.js'></script>
    <script type='text/javascript' src='dwr/engine.js'></script>
    <script type='text/javascript' src='dwr/util.js'></script>
    <!--script type="text/javascript" src="Page.js"></script-->
    <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();
}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>    </body>
</html>

解决方案 »

  1.   

    是因为缓存的缘故要在url 后面加上 时间戳 or 随机数
      

  2.   

    onclick="send('showrecords.jsp?r='+new Date());"
      

  3.   

    <input type="button" value="获取上传列表" onclick="send('showrecords.jsp?r='+Math.random());"/> 拜托,我也加啦``````
      

  4.   

    XMLHttpReq.open("GET",url,true); 
    =>
    XMLHttpReq.open("GET",url,true); 
    alert(url);运行一下,看看每次弹出的值
      

  5.   

    <xml id="Data" src="list.xml"> </xml> <!--设置要显示的xml--> 
    <xml id="Style" src="orders.xsl"> </xml> 我觉得是这两行有问题,我想也许是这里固定的设置了要显示的xml,这样它就只会在第一次加载时执行
    可我还是解决不了问题
      

  6.   

    那你先把 showrecords.jsp 里的代码 改下每次输出 当前时间在 js 中显示出来看看是不是没问题
      

  7.   

    function proce(){ 
    if(XMLHttpReq.readyState==4){ //对象状态 
    if(XMLHttpReq.status==200){//信息已成功返回,开始处理信息 
    //alert("window_onload````"); 
    //windows_onload();
    alert("Time````"+new Date()); //*****输出当前时间********
    }else{ 
    window.alert("所请求的页面有异常"); 


    } 能准确输出当前时间
      

  8.   

    不是的是你在showrecords.jsp 中输出当前时间然后 在 function proce(){ 
    if(XMLHttpReq.readyState==4){ //对象状态 
    if(XMLHttpReq.status==200){//信息已成功返回,开始处理信息 
    //alert("window_onload````"); 
    //windows_onload(); 
    alert(XMLHttpReq.responseText); //*****输出当前时间******** 
    }else{ 
    window.alert("所请求的页面有异常"); 



      

  9.   

    <input type="text" value="Time: +<%=new Date()%>"/>也还是输出时间呀,有什么用?