I have successfully implemented jQuery code that refreshes a specific div every 10 seconds
without reloading the entire page. However, during this refresh process, the user does not visually perceive any changes happening in the browser.
While there are numerous examples available online, I am specifically looking to enhance my existing script by displaying a loading gif image while the data is being fetched during the 10-second refresh interval. I want the user to see a refreshing image like the one below:
.
Though this may seem straightforward, I have been unable to find relevant information on how to achieve this. Any suggestions or guidance on this matter would be highly appreciated.
Problem Statement:-
The following code snippet represents the div in my JSP file (dataInfo.jsp)
, where I aim to reload the container
div every 10 seconds without having to reload the entire page.
<body>
<div id='headerDivDash'>
<h1 id='topHeaderDash'>
<!-- some image here -->
</h1>
</div>
<div id="vertical-list" style='display: block; list-style-type: none;'>
<ul class="resp-tabs-list">
<a href="_blank"><li>Test 1</li></a>
<br />
<a href="_blank"><li>Test 2</li></a>
</ul>
</div>
<!-- just need to reload this div, other div should be intact without getting appended -->
<div class="container">
</div>
<div class="footer">Some Value Here</div>
</body>
Below is the jquery script currently in use for loading the container div
every 30 seconds, which is functioning correctly:
<script type="text/javascript">
$(document).ready(function(){
var auto_refresh = setInterval(
function ()
{
$('.container').html('');
$('.container').load('dataInfo.jsp .container').fadeIn("slow");
}, 10 * 1000);
});
</script>
Considering my earlier request, I am seeking a way to gray out the container div
and display a refresh image during the ongoing refresh process. Once the refresh is completed, the normal content should reappear without the refresh image present.
Is it feasible to incorporate this feature into my current setup?