And yet another javascript clearInterval not working

I've seen a bunch of these threads and went through a few of them but nothing seemed to be of help so far. So I'm trying to call the timer continuously while the ajax call is taking place. Once the ajax call reaches the complete event, I'd like to clearInterval the timer, but that doesn't seem to be working because the call to CheckProgress() keeps going and going. Here's my code: var timer = ""; $("#ChartUpdateData").click(function () { $("#loadingimgfeatdiv").show(); //ajax loading gif if (timer == "") { console.log("Starting Progress Checks..."); timer = window.setInterval("CheckProgress()", 5000); } $.ajax({ type: "POST", async: true, url: '@(Url.Action("UpdateServerData","Charts"))', contentType: "application/json; charset=utf-8", success: function (data) { }, error: function (XMLHttpRequest, textStatus, errorThrown) { }, complete:function (jqXHR, textStatus) { $("#loadingimgfeatdiv").hide(); StopCheckingProgress(); LoadChart(); }, }); }); function StopCheckingProgress() { window.clearInterval(timer); timer = ""; console.log("Ending Progress Checks..."); } function CheckProgress() { console.log("Checking Progress..."); console.log(timer); } EDIT: ![enter image description here][1] [1]: http://i.stack.imgur.com/rju0o.png
Are you sure that your complete function is ever called? This may just be a problem with your AJAX request, and nothing to do with setInterval().

以上就是And yet another javascript clearInterval not working的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏