I am making admin portal, where admin can see the total number of current booking, for this we have to refresh table every 10 sec automatically and there wi
Try below code: - Use setInterval
1st Step :
You should create one common function which will fetch all data form Database
as below.
function fetchData(){
$(".data-contacts-js tbody").empty(); // this will remove all .
$.get("http://localhost:8080/Hotels/reservation/getAllBookingDetails", function(data) {
$.each(data, function(i, contact) {
$(".data-contacts-js").append(
" " + contact.custId + " " +
"" + contact.custName + " " +
"" + contact.custMobile + " " +
"" + contact.custEmail + " " +
"" + contact.custAddress + " " +
"" + contact.Date + " " +
"" + contact.Time + " "
);
});
});
}
Step 2:
Make function which will call function automatically in every 10 sec. using SetInterval
as below.
$(document).ready(function(){
setInterval(function(){
fetchData();
},10000); // this will call your fetchData function for every 10 Sec.
});
Step 3:
Make one event function for refresh
button click event
and put this function in .ready()
function.
$('#fetchContacts').click(function() {
fetchData();
});