【问题标题】:Ajax implementation on table portion of jsp pagejsp页面表格部分的ajax实现
【发布时间】:2015-02-27 07:10:36
【问题描述】:

我必须在一个表上实现 Ajax,这样我就可以在每次 !小时。我的 JSP 代码是

< head >
  < meta http - equiv = "Content-Type"
content = "text/html; charset=ISO-8859-1" >
  < title > Insert title here < /title>
 
     </head >

  < body >
 
< jsp: useBean id = "bs" class = "beam_Status.BeamStatus_Bean" > < /jsp:useBean>
 
 < br >
  < h1 > Total Beamlines open are $ { bs.total_Beamopen()} < /h1>
 
<CENTER><H1>BEAMLINE STATUS</H1 > < /CENTER>
   <center>
<table  border = "1" cellpadding="1" width="750px" id="ajax"> 
 
     <tr> 
      <th><h1><b>BEAMLINES</b > < /h1></th >
  < th > < h1 > < b > STATUS < /b></h1 > < /th> 
        <th><h1>SYMBOLIC REPRESENTATION</h1 > < /th>
    </tr >

  < c: forEach
var = "country"
items = "${bs.beam_CurrentStatus()}" >
  < h3 > < b >
  < c: choose >
  < c: when test = "${country.value == 'IN OPERATION'}" >
  < tr >
  < td class = "green"
style = "text-transform: uppercase; "
width = "400px" > < center > < h1 > $ {
    country.key
  } < /h1></center > < /td> 
                <td class="green" style="text-transform: uppercase; "width="300px"><center><h1> ${country.value}</h1 > < /center> </td >
  < td width = "200px" > < center > < img src = "red.png"
align = "middle"
width = "100"
height = "110" / > < /center></td >
  < /tr> 
   </c: when >
  < c: otherwise >
  < tr >
  < td class = "red"
style = "text-transform: uppercase; "
width = "400px" > < center > < h1 > $ {
    country.key
  } < /h1></center > < /td> 
               <td class="red" style="text-transform: uppercase; "width="300px"><center> <h1>${country.value}</h1 > < /center> </td >
  < td width = "200px" > < center > < img src = "green.png"
align = "middle"
width = "100"
height = "110" / > < /center></td >
  < /tr> 
  </c: otherwise >
  < /c:choose>
</b > < /h3>
    </c: forEach >

  < /table>
 
</center >

现在,整个页面都在刷新,我已经使用过了。

我对 Ajax 很陌生。请帮我在上面实现 Ajax。

【问题讨论】:

  • 大写锁定在尖叫。请修正您的文字,以免全部大写。
  • 从学习 Ajax 开始developer.mozilla.org/en-US/docs/AJAX/Getting_Started 然后你可以调用服务器,获取表格行并替换表格的内容。使用 setTimeout 触发下一次抓取。
  • @epascarello 感谢您的链接。但我无法理解要放入 httpRequest.onreadystatechange = function(){} 中的内容,就像在我的应用程序中一样,有一个按钮,当我点击表格时会更新。但我希望它自动更新。如何解决这个问题?如何使用 setTimeout ??

标签: javascript ajax jsp


【解决方案1】:

基本思路:

function reqListener () {
  var html = this.responseText;  //Server will return just the new html for the table
  document.getElementById("myTableWrapper").innerHTML = html;  //element around table you want to replace
}

var oReq = new XMLHttpRequest();
oReq.onload = reqListener;
oReq.onerror = function(){alert("error");};
oReq.open("get", "yourFileThatReturnsTheTable.php", true);
oReq.send();

了解您使用的技术。

【讨论】:

  • 非常感谢。但我仍然有一个愚蠢的问题,因为我从未在 jsp 中实现 ajax。我想问我必须创建两个 jsp 页面,一个用于 ajax,另一个用于 table,然后必须在 oReq.open 中传递 jsp 页面??我是否应该在我的 ajax jsp 页面中做其他事情??
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-13
  • 2010-09-08
  • 1970-01-01
  • 2012-12-28
  • 1970-01-01
相关资源
最近更新 更多