如何设置从阿贾克斯值的表JSP [英] How to set the values from the ajax to the table in jsp

查看:214
本文介绍了如何设置从阿贾克斯值的表JSP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JSP有一张桌子,在此我有两列名为状态和numRecords。 我收到通阿贾克斯新的状态和numrecords值。 我想做的是与阿贾克斯的新检索值替换状态和表numrecords。 我已经试过这样的,这是我的jsp:

I am having one jsp with a table,and in that i have two columns called status and numRecords. i am getting new status and numrecords values thru ajax. what i want to is replace status and numrecords of the table with the newly retrieved values on ajax. I have tried like this,this is my jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>

<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  
"http://www.w3.org/TR/html4/loose.dtd">
<html> 
    <head>
        <title>File Upload</title>
        <script type="text/javascript" src="js/jquery.min.js"></script>
       <link rel="stylesheet" type="text/css" href="css/style1.css" />
       <link rel="stylesheet" type="text/css" href="css/button.css" />
        <link href="css/common-style.css" rel="stylesheet" type="text/css" /> 
        <style>
        a{
        color:white;
        text-decoration:none;
        }
        </style>
         <script type="text/javascript">
        var id;
         function refreshRecord(value)
        {
            id = value;
            alert(id);
        }

        $(document).ready(function(){
            $("#refresh").click(function(){
               var fileId=id;
               alert("ajax id is "+fileId);
               $.ajax({
               type:'post',
                url:'checkStatusAndNumRecs',
               data:{fileId:fileId},
                success:function(data)
               {
                    var obj=data.split(':');
                    alert("status is :"+obj[0]);
                   $("#stat").html(obj[0]);
                   $("#recs").html(obj[1]);
               },
               error:function(data)
            {
                $("#div1").html("It was a failure !!!");
            }
                });
                });
                });
        </script>    
        </head>
    <body>
    <%@include file="index1.html" %>
    <div class="box2">    
     <div class="box3"> 
    <s:property value="userId"/>
    </div>  
        <center><h2>FILE STATUS</h2></center>
    <center> 

        <form action="Upload" method="post" enctype="multipart/form-data">
            <label for="myFile" class="text">Upload your file:</label>
            <input type="hidden" name="upload" value="upload"/>
            <input type="file" name="myFile" size="40"  class="file"/>
            <input type="submit" value="Upload" class="button"/>
            <input type="submit" value="Refresh" class="button"/>   
        </form>
        </center>        

          <center>
         <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 id="recs"><s:property value="%{#m.numRecords}" /></td>
            <td id="stat"><s:property value="%{#m.status}" /></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>
            <s:if test="%{user.roles == 'admin'}">
                 <td><a href=""><img src="images/details.png"></a>
                 <a href=""><img src="images/plus.png" title="Add Instance"></a>
                 <a href=""><img src="images/minus.png" title="Remove Instance"></a>
                 <a href=""><img src="images/download.png" title="Download"></a>
                 <a href=""><img src="images/reconnect.png" title="Reconnect"></a></td>

            </s:if>
            </tr>
         </s:iterator>
         </table>
         </center>

         <br>
         <br>
         <br>
         <br>  
         <center>
         <s:if test="%{user.roles == 'admin'}">

<!--          <select name="user names">
            <s:iterator value="userNamesList">
                <option value="emailColumn" > <s:property/>
                </option>
            </s:iterator>
        </select> -->

         <table border="1" class="displaytab" id="usertab">
         <s:if test="%{uploadListMap.size() != 0}">   
         <tr>   <td  colspan="10" style="background:#7395B8;color:white;font-size:18px;font-weight:bold;">User Job Details</center></td></tr>
         <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="%{uploadListMap}">
         <tr>   <td  colspan="10" style="background:#7395B8;color:white;font-size:18px;font-weight:bold;"><center><s:property value="key"/></center></td>
         <s:iterator value="value" var="u">
         <tr>
            <td><s:property value="%{#u.fileId}" /></td> 
            <td><s:property value="%{#u.fileName}" /></td>
            <td><s:property value="%{#u.uploadDate}" /></td>
            <td><s:property value="%{#u.numRecords}" /></td>
            <td><s:property value="%{#u.status}" /></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="%{#u.fileId}" />);"></a></td>
            <td><a href=""><img src="images/details.png"></a>
                 <a href=""><img src="images/plus.png" title="Add Instance"></a>
                 <a href=""><img src="images/minus.png" title="Remove Instance"></a>
                 <a href=""><img src="images/download.png" title="Download"></a>
                 <a href=""><img src="images/reconnect.png" title="Reconnect"></a></td>
         </tr>
         </s:iterator>
         </tr>
         </s:iterator>
         </s:if>
         </table>
         </s:if>
         </center> 
         </div>
    </body>
</html>

请帮我在这,在此先感谢。

please help me in this,thanks in advance.

推荐答案

如果你的动作返回JSON对象,如 {地位:成功,纪录:123} 然后设置的值,你可以使用

If your action returns JSON object like {"status":"success","records":"123"} then to set the values you could use

success:function(data) {
  alert(JSON.stringify(data));
  $("#stat").val(data.status);
  $("#recs").val(data.records);
}

这篇关于如何设置从阿贾克斯值的表JSP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆