[英]setInterval() firing but ajax update div content not working
在onDocumentReady(), $(function () {...})
,我有一行: window.setInterval("readPluginCache();", 3000);
readPluginCache()
方法将调用ajax调用,以检索和格式化名为$('#pluginCacheData')
元素的替换html。
我可以在Chrome浏览器(F12)中看到,每三秒钟记录一次Ajax启动,完成和成功事件(如预期的那样)。
但是,新的html不会替换旧的html值...我在页面上有一个按钮(作为备份),它调用readPluginCache()
方法; 有用!
如何使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;
}
好吧,我已经开始工作了; 但是我不确定为什么这样工作。我通过封装另一个称为readAll()的函数来抽象了原始的ajax调用,因此:window.setInterval(readAll,3000)。 readAll()依次调用三种不同的基于ajax的html / div修改方法。 我做了这个b / c,页面的其他部分也需要动态更新...对于我来说,为什么一个ajax调用不起作用时,为什么这个方法有效?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.