i have an ajax function which gets called and returns json data. this function is called via a setInterval loop:
function SetMaxBidReload() {
var reloadInt = 6000;
var doReload = true;
//set some logic here
if (doReload) {
setInterval(function () { ReloadMaxBid(); }, reloadInt);
}
}
function ReloadMaxBid() {
var nextReload;
$.ajax({
url: 'ajaxcall.aspx',
cache: false,
success: function (data) {
//change to dom elemants here based on return data
nextReload = data[0].NextReload;
}
});
return nextReload;
}
what im trying to do is change the reloadInt of setInterval based on what comes back from the ajax call.
a: is that possible and b: how do i do it?
im open to suggestions on how to accomplish this by coding it differently
setIntervaltakes the timeout param once and then executes the function based on that interval, changing thereloadIntwouldn’t have any effect whatsoever.You need to use
setTimeoutin the success callback:You’d also need to use
setTimeoutwith the value of6000somewhere to get things started.