刷新行并将行的两列替换为来自操作类的响应

Refreshing the row and replacing the two columns of a row with the responsegot from action class

本文关键字:操作 替换 响应 刷新 两列      更新时间:2023-09-26

我在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>

这是我使用 Ajax 的 JavaScript:

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"公共字符串执行() {

    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";
}

正在运行这个,在操作类中我正在获得状态和数字记录,问题是

  1. 只为第一行ajax函数在调用,其余行它不会进入ajax函数内部

  2. 我没有在 ajax 中获得状态和数字记录

3.datafrom Action 类应替换为"状态"和"#records"两列。请任何身体帮忙,我从几天开始就为此挣扎。

而且我没有使用 servlet,并且在表中我正在迭代数据列表。

我也遇到了这样的问题,我认为你的问题出在你的html表中。您已将刷新按钮放在表中。当 ajax 来到你的刷新按钮时,它无法读取按钮,并且发生异常,而不是不传递下一行。