[英]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.