我在每个行的jsp页面和刷新按钮中都有表格,并且每个刷新按钮都有一个javascript / ajax调用,其中它将转到动作类并获取状态值和#records并替换具有相应行的检索数据的列
这是我的jsp表:
<table border="1" class="displaytab" id="rtable">
<s:if test="%{user.roles == 'admin'}">
<tr> <td colspan="10" style="background:#7395B8;color:white;font-size:18px;font-weight:bold;"><center>Admin</center></td></tr>
</s:if>
<tr>
<th>FileId</th><th>File Name</th><th>Upload Date</th><th>#Records</th><th>Status</th><th>Estimated Time</th><th>Processed Records</th><th>Generate Report</th><th></th><s:if test="%{user.roles == 'admin'}"><th>Controls</th></s:if>
</tr>
<s:iterator value="uploadList" var="m">
<tr>
<td><s:property value="%{#m.fileId}" /></td>
<td><s:property value="%{#m.fileName}" /></td>
<td><s:property value="%{#m.uploadDate}" /></td>
<td><div id="div2"><s:property value="%{#m.numRecords}" /></div></td>
<td><div id="div1"><s:property value="%{#m.status}" /></div></td>
<td>tbd</td>
<td><s:property value="%{#m.numRecords}" /></td>
<td><a href=""><img src="images/generate.png" title="Generate Report"></a></td>
<td><a href=""><img src="images/refresh.png" title="Refresh" id="refresh" onclick="refreshRecord(<s:property value="%{#m.fileId}" />);"></a></td>
这是我的javascript with ajax:
var id;
function refreshRecord(value)
{
id = value;
alert(id);
}
$(document).ready(function(){
$("#refresh").click(function(){
var fileId=id;
alert("ajax id is "+fileId);
var rowNum = $(this).parent().parent().index();;
alert(rowNum);
$.ajax({
type:"post",
url:"checkStatusAndNumRecs",
data:{fileId:fileId},
success:function(data)
{
setTimeout(alert(data), 2000);
var allTds = $("#rtable tr:eq('"+rowNum+"')").find('td');
$(allTds)[4].html(data[0]);
$(allTds)[3].html(data[1]);
},
error:function(data)
{
$("#div1").html("It was a failure !!!");
}
});
});
});
</script>
这是我的动作类“checkStatusAndNumRecs” public String execute() {
System.out.println("here inside action-------------");
PersistenceService svc = PersistenceServiceImpl.getInstance();
status = svc.getStatusByFileId(fileId);
System.out.println("status is "+status);
numRecords = svc.getNumRecordsByFileId(fileId);
System.out.println("num records are "+numRecords);
return "SUCCESS";
}
我正在运行此功能,在动作类中我获得状态和numRecords, 问题是
仅针对第一行ajax函数正在调用,其余行不在ajax函数内部
我没有在ajax中获得状态和numRecords
3.datafrom action class应该替换为两列status和#records。 请任何身体帮助,我几天都在为此奋斗。
我没有使用servlet,在表格中我正在迭代数据列表。
答案 0 :(得分:0)
我也遇到这样的问题,我认为你的问题出现在你的html表中。你把刷新按钮放在你的表中。当ajax进入你的刷新按钮时它无法读取按钮并且发生异常而不是它没有通过下一行。