I need a js code for always getting the server time in a webpage. This code is working but not get the time dynamically. Code gets time one time while webpage loading.
$(document).ready(function() {
$.ajax({
type: "POST",
url: "GenericWCF.svc/GetSystemTime",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(bs) {
$("#systemTime").text(bs.d);
}
});
});
You need to use the window.setInterval method to call your function which performs your ajax call.
The window.setInterval method calls a function every X milliseconds repeatedly, until a call to window.clearInterval is called. Note that window.setInterval is “standard” javascript rather than jQuery.
For example:
Will call your ajax function every 1000 milliseconds (every second).