如何使用jquery / ajax刷新div中的表内容 [英] How to refresh table contents in div using jquery/ajax

查看:110
本文介绍了如何使用jquery / ajax刷新div中的表内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要你的帮助,以便在从方法中调用函数后,在我的html中刷新div id =mytable。目前,我正在使用以下行调用整页。

I need your help in order to refresh a div id="mytable" in my html once the function is called from a method. Currently, I am loading the full page once it is called using the below lines.

在我的java方法中,我使用以下行来调用javascript方法:

In my java method, I am using the below line to call a javascript method:

RequestContext.getCurrentInstance().execute("autoRefresh()"); 

html代码:

<script type="text/javascript">
    function autoRefresh() {
        window.location.reload();
    }
</script>

<div id='mytable'>
    <h1 id='My Table'>
        <table></table>
    </h1>
</div>


推荐答案

您可以加载HTML页面部分,在您的情况下是div内的所有内容#mytable。

You can load HTML page partial, in your case is everything inside div#mytable.

setTimeout(function(){
   $( "#mytable" ).load( "your-current-page.html #mytable" );
}, 2000); //refresh every 2 seconds

更多信息请阅读 http://api.jquery.com/load/

<button id="refresh-btn">Refresh Table</button>

<script>
$(document).ready(function() {

   function RefreshTable() {
       $( "#mytable" ).load( "your-current-page.html #mytable" );
   }

   $("#refresh-btn").on("click", RefreshTable);

   // OR CAN THIS WAY
   //
   // $("#refresh-btn").on("click", function() {
   //    $( "#mytable" ).load( "your-current-page.html #mytable" );
   // });


});
</script>

这篇关于如何使用jquery / ajax刷新div中的表内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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