I make an ajax call to get a milliseconds value which will be different on successive calls.
I display the value returned in an element.
I then want to take that value and use it as the time parameter in setTimeout.
When my function executes again, I want to reset the setTimeout time parameter with the new value returned.
Here's what I have, but it only executes once after the initial ten seconds:
var timeInterval = 10000;
setTimeout(function() {
$.ajax({
type: "POST",
url: "NowPlaying.asmx/GetMilliSeconds",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
$('#duration').html(msg.d.MilliSeconds);
clearTimeout(timeInterval);
timeInterval = msg.d.MilliSeconds;
}
});
}, timeInterval);
Is it possible to keep resetting timeInterval with different values based on successive calls to GetMilliSeconds?