我正在使用Spring MVC 在我的editStatus.jsp中,我有以下代码每5个seocnds刷新一次DIV
function refreshDiv(){
$.ajax({
url: 'editStatus.jsp'
}).done(function(result) {
$('#refreshDIV').text(result);
});
}
我的DIV代码是
<div class="span5">
<div class="row-fluid form-inline">
<h4 class="inline">
<spring:message code='alert.status' />
</h4>
</div>
<div class="row-fluid">
<div class="span5 row-fluid">
<div class="span9">
<div class="row-fluid">
<div class="span12">
<label>
<spring:message code='alert.sent' />:
</label>
</div>
</div>
<div class="row-fluid">
<div class="span12">
<label>
<spring:message code='alert.in.progress' />:
</label>
</div>
</div>
</div>
</div>
<!-- this has to be calculated, loop through 3 times seems excessive -->
<c:forEach var="channel" items="${StatusForm.channels}">
<c:set var="currentChannel" value=""></c:set>
<c:set var="channelIcon" value=""></c:set>
<c:if test="${channel == 'Email'}" >
<c:set var="currentChannel" value="EMAIL"></c:set>
<spring:url value="/static/img/icon_email_channel.png" var="channelIcon" />
</c:if>
<c:if test="${channel == 'SmsChannel'}" >
<c:set var="currentChannel" value="SMS"></c:set>
<spring:url value="/static/img/icon_sms_channel.png" var="channelIcon" />
</c:if>
<c:if test="${channel == 'VoiceChannel'}" >
<c:set var="currentChannel" value="VOICE"></c:set>
<spring:url value="/static/img/icon_voice_channel.png" var="channelIcon" />
</c:if>
<div id="refreshDiv" class="span3" >
<c:set var="map" value="${StatusForm.channelStateForRecipients[currentChannel]}"></c:set>
<div>
<label style="color:black" ><img src="${channelIcon}">
${fn:length(StatusForm.totalSentRecipient)}
</label>
</div>
<div>
<label style="color:black"><img src="${channelIcon}">
${fn:length(StatusForm.totalNotSentRecipient)}
</label>
</div>
<div>
<label style="color:black"><img src="${channelIcon}">
${fn:length(StatusForm.totalInProgressRecipient)}
</label>
</div>
</div>
</c:forEach>
</div>
</div>
从上面的代码我想自动刷新以下内容,但是同样不起作用
<div id="refreshDiv" class="span3" >
<c:set var="map" value="${StatusForm.channelStateForRecipients[currentChannel]}"></c:set>
<div>
<label style="color:black" ><img src="${channelIcon}">
${fn:length(StatusForm.totalSentRecipient)}
</label>
</div>
<div>
<label style="color:black"><img src="${channelIcon}">
${fn:length(StatusForm.totalNotSentRecipient)}
</label>
</div>
<div>
<label style="color:black"><img src="${channelIcon}">
${fn:length(StatusForm.totalInProgressRecipient)}
</label>
</div>
</div>
URL刷新代码是否应通过控制器?
我试过
$(document).ready(function () {
alert('Hi OutBound');
var seconds = 5000; // time in milliseconds
var reload = function() {
alert('Inside Reload');
$.ajax({
url: 'editStatus.jsp',
cache: false,
success: function(data) {
alert('Inside 2');
$('#refreshDIV').html(data);
setTimeout(function() {
alert('Inside SettimeOut');
reload();
}, seconds);
}
});
};
reload();
});
然而警报提醒('内部2');和警报('内部SettimeOut');永远不会被打电话 请建议
答案 0 :(得分:4)
我认为你的刷新功能是不完整的,例如没有什么可以让它循环。尝试这样的事情:
$(document).ready(function () {
var seconds = 5000; // time in milliseconds
var reload = function() {
$.ajax({
url: 'editStatus.jsp',
cache: false,
success: function(data) {
$('#refreshDIV').html(data);
setTimeout(function() {
reload();
}, seconds);
}
});
};
reload();
});