gpt4 book ai didi

javascript - 如何使用 jquery/ajax 刷新 div 中的表格内容

转载 作者:行者123 更新时间:2023-11-30 07:08:19 25 4
gpt4 key购买 nike

我需要你的帮助,以便在从方法调用函数后刷新我的 html 中的 div id="mytable"。目前,一旦使用以下行调用它,我就会加载整个页面。

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

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 中的所有内容。

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>

关于javascript - 如何使用 jquery/ajax 刷新 div 中的表格内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30254977/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com