我正在尝试构建一个小型JMS监视器,
后端:计划的EJB任务每分钟检索一次JMS状态并将域统计信息写入JSON文件
frontend:使用JQuery“getJSON()”检索存储在服务器上的JSON文件中的内容,并根据这些内容构建html内容。
问题:前端JQuery设置为每30秒获取一次JSON文件,它在第一次尝试时工作正常,但是,当在服务器上更新文件时,JQuery没有获得更新的版本这个JSON文件。它不断得到旧的。
我的猜测是它加载了初始文件并将其存储在browers缓存中,我试图通过调用“$ .ajaxSetup({cache:false})来阻止它使用缓存;”,它没有解决但是这个问题。
有什么想法吗?非常感谢!!
代码段:
setInterval(getCache,30000);
$(document).ready(function() {
getCache();
});
function getCache(){
$.ajaxSetup({ cache: false });
$.getJSON('historyQueueJSON.json', function(results) {
var domain_list = "";
$.each(results.domains, function(){
domain_list = domain_list + "<ul data-role=\"listview\" data-inset=\"true\" data-dividertheme=\"a\">";
domain_list = domain_list + "<li data-role=\"list-divider\">"+ this.domain + "</li>";
//domain_list = domain_list + "<li data-theme = \"e\">Number of Queues<span class=\"ui-li-count\">" + this.queues.length+ "</span></li>";
$.each(this.queues, function(){
var str = this.history.toString();
str = str.substring(1,str.length-1);
if (this.count > 100 ){
domain_list = domain_list + "<li data-theme = \"e\"><h3>" + this.queue + "</h3><p>Last Enqueue Time: " + this.timeOnQueue + " minutes ago</p><p class=\"dynasparkline\">"+str+"</p><span class=\"ui-li-count\">" + this.count + "</span></li>";
} else if ( this.enqueueTime > 30 ){
domain_list = domain_list + "<li data-theme = \"b\"><h3>" + this.queue + "</h3><p>Last Enqueue Time: " + this.timeOnQueue + " minutes ago</p><span class=\"ui-li-count\">" + this.count + "</span><p class=\"dynasparkline\">"+str+"</p></li>";
} else {//if (this.count > 10 ){
domain_list = domain_list + "<li data-theme = \"c\"><h3>" + this.queue + "</h3><p>Last Enqueue Time: " + this.timeOnQueue + " minutes ago</p><span class=\"ui-li-count\">" + this.count + "</span><p class=\"dynasparkline\">"+str+"</p></li>";
}
});
domain_list = domain_list + "</ul><br/>";
});
var now =results.updatedTS;
document.getElementById("domain").innerHTML = domain_list;
document.getElementById("lastupdate").innerHTML = now;
$('.dynasparkline').sparkline();
$('#domain').trigger("create");
});
$('#spk').sparkline();
};
</script>