I have a jsp which consists a table, The table is displaying some data which is coming from Database. Now I want to refresh only the table for every 30 seconds. Kindly help me out to solve this issue. Please find the below code.
Note: I don't want to refresh the whole page. only i want to refresh the table in jsp.
empDetails.jsp
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<body>
<center><h2>Employee Details</h2></center>
<form>
<center>
<div id="loadData">
<table border="2">
<c:if test="${!empty empDetails}">
<tr>
<th>Employee ID</th>
<th>Employee Name</th>
<th>Salary</th>
<th>Department</th>
</tr>
<c:forEach items="${empDetails}" var="emp">
<tr>
<td><c:out value="${emp.empId}"/></td>
<td><c:out value="${emp.empName}"/></td>
<td><c:out value="${emp.salary}"/></td>
<td><c:out value="${emp.department}"/></td>
</tr>
</c:forEach>
</c:if>
</table>
</div>
</center>
</form>
</body>
</html>
function refreshFunction(){
$.ajax({
url: '/page.html', //page or method that will return html
success: function (data) {
$('div#loadData').html(data);
}
});
}
setInterval(refreshFunction, /*interval*/)
See $.ajax, it has a lot of useful parameters.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.