Done by callback.
function settimer() {
alert('timer fired');
setTimeout(function () {
createNotificTable(function () {
settimer();
});
}, 5000)
}
function createNotificTable(callback) {
var tbl = $("#gridNotificInbox tbody");
var empid = $("#hdnempidmaster").val();
var maxid = 0;
if (parseInt($('#gridNotificInbox tbody tr').length) > 0) {
maxid = Math.max.apply(Math, $("#gridNotificInbox tbody tr td:first-child").map(function () {
return $(this).text();
}));
}
alert(maxid);
$.ajax({
type: "POST",
url: "notification.aspx/ReturnTableRow",
data: JSON.stringify({ maxidfetched: maxid, empid: empid }),
contentType: "application/json; charset=utf-8",
dataType: "json",
beforeSend: function () {
},
success: function (response) {
if (response.d.trim() != "") {
initializeDatatable(response.d);
}
callback();
},
failure: function (response) {
}
});
}