title: Refreshing (updating) individual rows of a table with the data returned by the action class using ajax call
body: <p>from so many days i am trying to get this done,but m failing.
  Have a look at my jsp once below:</p>
  
  <p>Here i have one table and all each row i have refresh icon,i want to refresh individual row when clicked the icon.</p>
  
  <p>onclick i am calling a function-> <code>refreshRecord(value);</code> value(parameter) is the fileid(unique)->i.e the first column of the table i am passing as a parameter to the function.</p>
  
  <p><code>ajax</code> is calling the <code>checkStatusAndNumRecs</code> aciton with the <code>fileId</code>,in action class i am calling my <code>JPA</code> method to get data from the database,its reading the row with that <code>fileId</code> what i have passed and putting it in <code>JSONObject</code>.</p>
  
  <p>In jsp in ajax part its executing suuccess some time and error its executing most of the time,
  when it is success,inside success part ,its failing to execute this line->var <code>obj = jQuery.parseJSON(eval(data));</code></p>
  
  <p>that means some times data is returning to ajax sometimes data is not coming back to ajax from action class.</p>
  
  <p>THis is my jsp page:</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  pageEncoding="ISO-8859-1"%&gt;
  
  &lt;%@ taglib prefix="s" uri="/struts-tags"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  
  "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt; 
      &lt;head&gt;
          &lt;title&gt;File Upload&lt;/title&gt;
          &lt;script type="text/javascript" src="js/jquery-1.4.1.min.js"&gt;&lt;/script&gt;
          &lt;script type="text/javascript" src="js/jquery-1.8.2.min.js"&gt;&lt;/script&gt;
          &lt;script type="text/javascript" src="js/jquery.min.js"&gt;&lt;/script&gt;
         &lt;link rel="stylesheet" type="text/css" href="css/style1.css" /&gt;
         &lt;link rel="stylesheet" type="text/css" href="css/button.css" /&gt;
          &lt;link href="css/common-style.css" rel="stylesheet" type="text/css" /&gt; 
          &lt;style&gt;
          a{
          color:white;
          text-decoration:none;
          }
          &lt;/style&gt;
           &lt;script type="text/javascript"&gt;
          var id;
           function refreshRecord(value)
          {
              id = value;
          }
  
          $(document).ready(function(){
              $("#refresh").click(function(){
                 var fileId=id;
                 $.ajax({
                 type:"post",
                  url:"checkStatusAndNumRecs",
                 data:{fileId:fileId},
                  success:function(data)
                 {
                      alert(data);
                      var obj = jQuery.parseJSON(eval(data));-&gt;THis statement is not executing
                      aler("after JSON OBJECT"+obj.status);
                     $("#div1").html(obj.status);
                     $("#div2").html(obj.records);
                 },
                 error:function(data)
              {
                  $("#div1").html("It was a failure !!!");
              }
                  });
                  });
            });
          &lt;/script&gt;    
          &lt;/head&gt;
      &lt;body&gt;
      &lt;%@include file="index1.html" %&gt;
      &lt;div class="box2"&gt;    
       &lt;div class="box3"&gt; 
      &lt;s:property value="userId"/&gt;
      &lt;/div&gt;  
          &lt;center&gt;&lt;h2&gt;FILE STATUS&lt;/h2&gt;&lt;/center&gt;
      &lt;center&gt; 
  
          &lt;form action="Upload" method="post" enctype="multipart/form-data"&gt;
               &lt;label for="myFile" class="text"&gt;Upload your file:&lt;/label&gt;
              &lt;input type="hidden" name="upload" value="upload"/&gt;
              &lt;input type="file" name="myFile" size="40"  class="file"/&gt;
              &lt;input type="submit" value="Upload" class="button"/&gt;
              &lt;input type="submit" value="Refresh" class="button"/&gt;
          &lt;/form&gt;
  
          &lt;/center&gt;
          &lt;center&gt;    
             &lt;s:if test="%{user.roles == 'admin'}"&gt;
          &lt;form action="manage" method="post" enctype="multipart/form-data"&gt;
              &lt;label for="myFile" class="text"&gt;Click to manage service providers:&lt;/label&gt;
              &lt;input type="submit" value="Manage" class="button"/&gt;
          &lt;/form&gt;
          &lt;/s:if&gt;
          &lt;/center&gt;
            &lt;center&gt;
           &lt;table border="1" class="displaytab" id="rtable"&gt;
           &lt;s:if test="%{user.roles == 'admin'}"&gt;
           &lt;tr&gt;   &lt;td  colspan="10" style="background:#7395B8;color:white;font-size:18px;font-weight:bold;"&gt;&lt;center&gt;Admin&lt;/center&gt;&lt;/td&gt;&lt;/tr&gt;
           &lt;/s:if&gt;
           &lt;tr&gt; 
           &lt;th&gt;FileId&lt;/th&gt;&lt;th&gt;File Name&lt;/th&gt;&lt;th&gt;Upload Date&lt;/th&gt;&lt;th&gt;#Records&lt;/th&gt;&lt;th&gt;Status&lt;/th&gt;&lt;th&gt;Estimated Time&lt;/th&gt;&lt;th&gt;Processed Records&lt;/th&gt;&lt;th&gt;Generate Report&lt;/th&gt;&lt;th&gt;&lt;/th&gt;&lt;s:if test="%{user.roles == 'admin'}"&gt;&lt;th&gt;Controls&lt;/th&gt;&lt;/s:if&gt;
           &lt;/tr&gt;
  
           &lt;s:iterator value="uploadList" var="m"&gt; 
              &lt;tr&gt;   
              &lt;td&gt;&lt;s:property value="%{#m.fileId}" /&gt;&lt;/td&gt; 
              &lt;td&gt;&lt;s:property value="%{#m.fileName}" /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;s:property value="%{#m.uploadDate}" /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;div id="div2"&gt;&lt;s:property value="%{#m.numRecords}" /&gt;&lt;/div&gt;&lt;/td&gt;
              &lt;td&gt;&lt;div id="div1"&gt;&lt;s:property value="%{#m.status}" /&gt;&lt;/div&gt;&lt;/td&gt;
              &lt;td&gt;tbd&lt;/td&gt;
  
              &lt;td&gt;&lt;s:property value="%{#m.numRecords}" /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;a href=""&gt;&lt;img src="images/generate.png" title="Generate Report"&gt;&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;&lt;a href=""&gt;&lt;img src="images/refresh.png" title="Refresh" id="refresh" onclick="refreshRecord(&lt;s:property value="%{#m.fileId}" /&gt;);"&gt;&lt;/a&gt;&lt;/td&gt;
              &lt;s:if test="%{user.roles == 'admin'}"&gt;
                   &lt;td&gt;&lt;a href=""&gt;&lt;img src="images/details.png"&gt;&lt;/a&gt;
                   &lt;a href=""&gt;&lt;img src="images/plus.png" title="Add Instance"&gt;&lt;/a&gt;
                   &lt;a href=""&gt;&lt;img src="images/minus.png" title="Remove Instance"&gt;&lt;/a&gt;
                   &lt;a href=""&gt;&lt;img src="images/download.png" title="Download"&gt;&lt;/a&gt;
                   &lt;a href=""&gt;&lt;img src="images/reconnect.png" title="Reconnect"&gt;&lt;/a&gt;&lt;/td&gt;
  
              &lt;/s:if&gt;
              &lt;/tr&gt;
           &lt;/s:iterator&gt;
           &lt;/table&gt;
           &lt;/center&gt;
  
           &lt;br&gt;
           &lt;br&gt;
           &lt;br&gt;
           &lt;br&gt;  
           &lt;center&gt;
           &lt;s:if test="%{user.roles == 'admin'}"&gt;
  
  &lt;!--          &lt;select name="user names"&gt;
              &lt;s:iterator value="userNamesList"&gt;
                  &lt;option value="emailColumn" &gt; &lt;s:property/&gt;
                  &lt;/option&gt;
              &lt;/s:iterator&gt;
          &lt;/select&gt; --&gt;
  
           &lt;table border="1" class="displaytab" id="usertab"&gt;
           &lt;s:if test="%{uploadListMap.size() != 0}"&gt;   
           &lt;tr&gt;   &lt;td  colspan="10" style="background:#7395B8;color:white;font-size:18px;font-weight:bold;"&gt;User Job Details&lt;/center&gt;&lt;/td&gt;&lt;/tr&gt;
           &lt;tr&gt; 
           &lt;th&gt;FileId&lt;/th&gt;&lt;th&gt;File Name&lt;/th&gt;&lt;th&gt;Upload Date&lt;/th&gt;&lt;th&gt;#Records&lt;/th&gt;&lt;th&gt;Status&lt;/th&gt;&lt;th&gt;Estimated Time&lt;/th&gt;&lt;th&gt;Processed Records&lt;/th&gt;&lt;th&gt;Generate Report&lt;/th&gt;&lt;th&gt;&lt;/th&gt;&lt;s:if test="%{user.roles == 'admin'}"&gt;&lt;th&gt;Controls&lt;/th&gt;&lt;/s:if&gt;
           &lt;/tr&gt;
           &lt;s:iterator  value="%{uploadListMap}"&gt;
           &lt;tr&gt;   &lt;td  colspan="10" style="background:#7395B8;color:white;font-size:18px;font-weight:bold;"&gt;&lt;center&gt;&lt;s:property value="key"/&gt;&lt;/center&gt;&lt;/td&gt;
           &lt;s:iterator value="value" var="u"&gt;
           &lt;tr&gt;
              &lt;td&gt;&lt;s:property value="%{#u.fileId}" /&gt;&lt;/td&gt; 
              &lt;td&gt;&lt;s:property value="%{#u.fileName}" /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;s:property value="%{#u.uploadDate}" /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;s:property value="%{#u.numRecords}" /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;s:property value="%{#u.status}" /&gt;&lt;/td&gt;
              &lt;td&gt;tbd&lt;/td&gt;
              &lt;td&gt;&lt;s:property value="%{#m.numRecords}" /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;a href=""&gt;&lt;img src="images/generate.png" title="Generate Report"&gt;&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;&lt;a href=""&gt;&lt;img src="images/refresh.png" title="Refresh" id="refresh" onclick="refreshRecord(&lt;s:property value="%{#u.fileId}" /&gt;);"&gt;&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;&lt;a href=""&gt;&lt;img src="images/details.png"&gt;&lt;/a&gt;
                   &lt;a href=""&gt;&lt;img src="images/plus.png" title="Add Instance"&gt;&lt;/a&gt;
                   &lt;a href=""&gt;&lt;img src="images/minus.png" title="Remove Instance"&gt;&lt;/a&gt;
                   &lt;a href=""&gt;&lt;img src="images/download.png" title="Download"&gt;&lt;/a&gt;
                   &lt;a href=""&gt;&lt;img src="images/reconnect.png" title="Reconnect"&gt;&lt;/a&gt;&lt;/td&gt;
           &lt;/tr&gt;
           &lt;/s:iterator&gt;
           &lt;/tr&gt;
           &lt;/s:iterator&gt;
           &lt;/s:if&gt;
           &lt;/table&gt;
           &lt;/s:if&gt;
           &lt;/center&gt; 
           &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is my action class:</p>
  
  <p>p</p>
  
  <pre><code>ackage com.mxui;
  
  import com.mxui.db.api.PersistenceService;
  import com.mxui.db.service.*;
  import org.json.simple.JSONObject;
  
  import com.opensymphony.xwork2.ActionSupport;
  
  public class checkStatusAndNumRecsAction extends ActionSupport
  {
      /**
       * 
       */
  
      private String status;
  
      public String getStatus()
      {
          return status;
      }
  
      public void setStatus(String status) 
      {
          this.status = status;
      }
  
      private long numRecords;
  
      public long getNumRecords()
      {
          return numRecords;
      }
  
      public void setNumRecords(long  numRecords) 
      {
          this.numRecords= numRecords;
      }
  
      private String fileId;
         public String getFileId()
      {
          return fileId;
      }
  
      public void setFileId(String fileId) 
      {
          this.fileId = fileId;
      }
  
      public String execute()
      {  
          JSONObject obj = new JSONObject();
          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);
          obj.put("status", status);
          obj.put("records", numRecords);
          System.out.print("json data is "+obj);
          return "SUCCESS";
      }
  }
  </code></pre>
  
  <p>Please guide me in this ,i am struggling for this from so many days,and also i am new to ajax.
  Thankyou in advance.</p>
  
  <pre><code>This is my struts.xml file:
  
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE struts PUBLIC
  "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
  "http://struts.apache.org/dtds/struts-2.0.dtd"&gt;
  
  &lt;struts&gt;
     &lt;constant name="struts.devMode" value="false" /&gt;
     &lt;constant name="struts.multipart.maxSize" value="1000000" /&gt;
     &lt;result-type name="json" class="org.apache.struts2.json.JSONResult" default="false" /&gt;
  
     &lt;package name="struts" extends="struts-default"&gt;   
      &lt;action name="RegisterationProcess" class="com.mxui.RegisterationFormAction"&gt;
       &lt;result name="SUCCESS"&gt;registerationform.jsp&lt;/result&gt;
       &lt;result name="customerRegister"&gt;successregisteration.jsp&lt;/result&gt;     
     &lt;/action&gt;
  
       &lt;action name="CheckUserValidation" class="com.mxui.CheckUserAction"&gt;
       &lt;result name="SUCCESS"&gt;noofrows.jsp&lt;/result&gt;
       &lt;/action&gt;
  
     &lt;action name="ProcessLogin" class="com.mxui.LoginAction"&gt;
         &lt;result name="LOGIN" &gt;login.jsp&lt;/result&gt;
         &lt;result name="REGISTER"&gt;registerationform.jsp&lt;/result&gt;
         &lt;result name="ERROR" type="redirect"&gt;login.jsp&lt;/result&gt;
         &lt;result name="FILEUPLOAD"  type="redirect"&gt;Upload&lt;/result&gt;   
      &lt;/action&gt;    
  
        &lt;action name="Upload" class="com.mxui.UploadFileAction"&gt;        
        &lt;result name="SUCCESS"&gt;fileupload.jsp&lt;/result&gt;       
        &lt;result name="LOGINERROR" type="redirect"&gt;ProcessLogin&lt;/result&gt;
        &lt;result name="PREVIEW" type="redirect"&gt;FilePreviewAction&lt;/result&gt;       
        &lt;result name="ERROR"&gt;error.jsp&lt;/result&gt;
        &lt;/action&gt;   
  
     &lt;action name="FilePreviewAction" class="com.mxui.FilePreviewAction"&gt;
       &lt;result name="SUCCESS"&gt;filepreview.jsp&lt;/result&gt;
      &lt;result name="JOBCREATED" type="redirect"&gt;Upload&lt;/result&gt;
      &lt;result name="ERROR" type="redirect"&gt;ProcessLogin&lt;/result&gt;  
     &lt;/action&gt; 
  
     &lt;action name="ServiceProviderProcess" class="com.mxui.ServiceProviderAction"&gt;
       &lt;result name="SUCCESS"&gt;CreateProvider.jsp&lt;/result&gt;
       &lt;result name="serviceprovider" type="redirect"&gt;Upload&lt;/result&gt;     
     &lt;/action&gt;
  
     &lt;action name="UpdateServiceProviderProcess" class="com.mxui.UpdateServiceProviderAction"&gt;
       &lt;result name="SUCCESS"&gt;updateserviceprovider.jsp&lt;/result&gt;
       &lt;result name="updated" type="redirect"&gt;Upload&lt;/result&gt;     
     &lt;/action&gt;
  
     &lt;action name="manage" class="com.mxui.ManageServiceProviderAction"&gt;    
     &lt;result name="SUCCESS"&gt;manageserviceprovider.jsp&lt;/result&gt;   
        &lt;/action&gt;
     &lt;/package&gt;
  
     &lt;package extends="struts-default,json-default" name="name" namespace=""&gt;
     &lt;interceptor name="json" class="org.apache.struts2.json.JSONInterceptor" /&gt;
  
     &lt;action name="checkStatusAndNumRecs" class="com.mxui.checkStatusAndNumRecsAction" method="execute"&gt;
           &lt;result type="json"&gt;&lt;/result&gt;
     &lt;/action&gt;
  &lt;/package&gt;
  &lt;/struts&gt;
  </code></pre>