2013-09-24 30 views
1

HI我在JSP页面中有一个表格,在行级别有刷新按钮,当我点击刷新按钮时,它应该检查数据库并获取这两列并替换旧值即刷新。在jsp中使用ajax刷新按钮的列onclick

这是我下面的jsp页面。

<script src="js/jquery1.min.js"></script> 
<script 
<script type="text/javascript"> 
function refreshRecord(id) 
{ 
    $(document).ready(function(){ 
    $("#buto").click(function(){ 
    $(this).parents('tr').find(".b1").load(".b1"); 
    $(this).parents('tr').find(".b2").load(".b2"); 
    alert("value"); 
    }); 
    }); 
} 
    <table border="1" class="displaytab" id="rtable"> 
    <tr> 
    <th>#Records</th><th>Status</th><th>Estimated Time</th><th></th> 
    </tr> 

    <s:iterator value="uploadList" var="m"> 
      <tr> 
      <td class="b1"><s:property value="%{#m.numRecords}" /></td> 
      <td class="b2"><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="buto" onclick="refreshRecord(<s:property value="%{#m.fileId}" />);"></a></td> 
      </tr> 
     </s:iterator> 
     </table> 

任何机构可以帮助这个 感谢提前

回答

0
+0

三江源,但我使用JPA和没有PHP中,你可以通过使用这些帮助。 – raajiv

+0

Java Persistent API,对不对?你告诉JSP。所以我猜你的应用程序的视图是JSP。你需要什么是;一个可以从数据库中获取的javaClass,并且可以在JsonArray中给你一个输出(如果可能的话)。我没有在JPA工作过。所以我不知道它是否可能。 – smilyface

+0

还有一件事。 Ajax不是一种语言。简而言之,它就是javascript本身。所以它可以用于HTML,PHP,JSP等等。 – smilyface

0

了解如何AJAX的作品简单的HTML ... 如果你学会了这一点,很容易让你实现你的应用程序相同的

将这个HTML保存在一个文件夹中[比如说ajaxFolder]。

<!DOCTYPE html> 
<html> 
<head> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"> 
</script> 
<script> 
$(document).ready(function(){ 
    $("button").click(function(){ 
    $.ajax({ 
     url:"somePath/testMe.txt", //pls specify correct path of text file and enter something in the file. 
     success:function(result){$("#div1").html(result);}, 
     error:function(result){$("#div1").html("It was a fuilure !!!");} 
    }); 
    }); 
}); 
</script> 
</head> 
<body> 

<div id="div1"><h2>Click the button. Ajax will take data from the text file and will show you here.</h2></div> 
<button>Get External Content</button> 

</body> 
</html> 

保存somePath/testMe.txt的地方,并在其中输入一些数据。

+0

我跑它显示失败只不知道为什么? – raajiv

+0

好吧,我知道了,但是,该行动类将返回两个不同的变量值,我必须在同一行中显示在两个不同的列如何我可以做到这一点,你可以请帮助 – raajiv

+0

这就是为什么我告诉Json我的第一个评论。在你的动作文件中,把你的两个变量放到一个jSon中。然后将其发送到JSP。通过ajax获取它。提取json(它就像一个键值对)。将第一个键的值放在第一行。第二排在第二位。 – smilyface

1

这里是另一个HTML与你想要的东西。

<html> 
    <head> 

    <style> 
     button{color:#127DDB;padding:8px 15px;background-color:#C1DFFA;margin-top:20px;} 
     #div1{background-color:#F7FBC9;border:1px solid #F8053E} 
     #div2{background-color:#FBDCC9;border:1px solid #F8053E} 
    </style> 

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"/> 

    <script language="javascript"> 
    $(document).ready(function(){ 
     $("button").click(function(){ 
     $.ajax({ 
      url:"testMe.txt", //pls specify correct path of text file and enter json string. 
      success:waawSuccess, 
      error:ohNoFailure 
     }); 
     }); 

     function waawSuccess(result){ 
      var obj = jQuery.parseJSON(eval(result)); 
      $("#div1").html(obj.name); 
      $("#div2").html(obj.place); 
     } 

     function ohNoFailure(result){ 
      $("#div1").html("It was a fuilure !!!"); 
     } 

    }); 
    </script> 
    </head> 
    <body> 

    <table border="1"> 
    <tr> 
     <td><div id="div1">old name</div></td> 
    </tr> 
    <tr> 
     <td><div id="div2">old place</div></td> 
    </tr> 
    <tr> 
     <td>House</td> 
    </tr> 
    <tr> 
     <td>School</td> 
    </tr> 
    </table> 

    <button>Run ajax and print here without page refresh!</button> 

    </body> 
    </html> 

testMe.txt

'{ "name": "John", "place" : "Chicago" }' 
+0

非常感谢,但如果我不使用文本文件,instesd直接我想使用操作类的数据,我实际上没有使用任何文本文件。在行动类我有两个数据变量。 – raajiv