Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
146
rated 0 times [  152] [ 6]  / answers: 1 / hits: 149763  / 9 Years ago, fri, may 15, 2015, 12:00:00

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.



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



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


The html code :



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

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

More From » jquery

 Answers
21

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


more information read this http://api.jquery.com/load/



Update Code (if you don't want it auto-refresh)



<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>

[#66597] Wednesday, May 13, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kevonmoisesf

Total Points: 693
Total Questions: 101
Total Answers: 128

Location: Reunion
Member since Mon, Dec 28, 2020
4 Years ago
kevonmoisesf questions
Sat, Jan 23, 21, 00:00, 3 Years ago
Tue, Feb 18, 20, 00:00, 4 Years ago
Wed, Jun 12, 19, 00:00, 5 Years ago
;