[英]setInterval() firing but ajax update div content not working
In the onDocumentReady(), $(function () {...})
, I have a line: window.setInterval("readPluginCache();", 3000);
在
onDocumentReady(), $(function () {...})
,我有一行: window.setInterval("readPluginCache();", 3000);
The readPluginCache()
method invokes an ajax call to retrieve and format replacement html for a named $('#pluginCacheData')
element. readPluginCache()
方法将调用ajax调用,以检索和格式化名为$('#pluginCacheData')
元素的替换html。
I can see in Chrome (F12) that the ajax start, complete and success events are being recorded every three seconds (as expected). 我可以在Chrome浏览器(F12)中看到,每三秒钟记录一次Ajax启动,完成和成功事件(如预期的那样)。
However, the new html isn't replacing the old html values... I have a button on the page (as a backup) and it calls the readPluginCache()
method; 但是,新的html不会替换旧的html值...我在页面上有一个按钮(作为备份),它调用
readPluginCache()
方法; it works! 有用!
How do I make the setInterval()
methodology to work? 如何使
setInterval()
方法起作用?
function readPluginCache() {
if (!isAuthorized) {
addMessageError("Error: Unauthorized readCache attempt.");
return false;
}
$('#pluginCacheData').hide();
$.ajax({
type: "POST",
url: infoPageName + "/BriskPluginCacheInfoHtml",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json"
}).done(function (response) {
$('#pluginCacheData').empty();
$('#pluginCacheData').append(response.d);
}).fail(function (jqXHR, exception) {
if (jqXHR.responseText.toLowerCase().indexOf('html') !== -1) {
addMessageError("Internal Server Error: readPluginCache(). Please check the event log.");
}
else
addMessageError("Error: " + jqXHR.responseJSON.Message);
alert(exception);
}).always(function () {
$('#pluginCacheData').show();
});
return true;
}
Okay, I got it working; 好吧,我已经开始工作了; but I'm not sure why this works... I have abstracted the original ajax call by encapsulating it another function called readAll(), so: window.setInterval(readAll, 3000).
但是我不确定为什么这样工作。我通过封装另一个称为readAll()的函数来抽象了原始的ajax调用,因此:window.setInterval(readAll,3000)。 The readAll() calls three different ajax-based html/div modifying methods sequentially.
readAll()依次调用三种不同的基于ajax的html / div修改方法。 I did this b/c there are other parts of the page that also need to dynamically update... It's a mystery to me why this works when one ajax call didn't.
我做了这个b / c,页面的其他部分也需要动态更新...对于我来说,为什么一个ajax调用不起作用时,为什么这个方法有效?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.