99m*_*aas 1 javascript ajax xhtml jquery
我需要你的帮助,以便id="mytable"在从方法调用函数后刷新html中的div .目前,我使用以下行调用完整页面.
在我的java方法中,我使用下面的行来调用javascript方法:
RequestContext.getCurrentInstance().execute("autoRefresh()");
Run Code Online (Sandbox Code Playgroud)
HTML代码:
<script type="text/javascript">
function autoRefresh() {
window.location.reload();
}
</script>
<div id='mytable'>
<h1 id='My Table'>
<table></table>
</h1>
</div>
Run Code Online (Sandbox Code Playgroud)
Ary*_*owo 10
你可以加载HTML页面部分,在你的情况下是div#mytable里面的一切.
setTimeout(function(){
$( "#mytable" ).load( "your-current-page.html #mytable" );
}, 2000); //refresh every 2 seconds
Run Code Online (Sandbox Code Playgroud)
更多信息请阅读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>
Run Code Online (Sandbox Code Playgroud)