我有这样的jQuery脚本定期更新只发生一次
<script>
(function worker() {
$.ajax({
dataType: 'json',
url: '/course.json',
success: function(data) {
$('#current').text(data);
},
complete: function() {
// Schedule the next request when the current one's complete
setTimeout(worker, 1000);
}
});
})();
</script>
这只有一次。一次更新后,即使Ajax响应发生变化,#current
的值也不会改变。
如果这个问题是关系到改变DOM属性,我不知道我如何使用.delegate
这里有像click
没有实际事件等
@FarzinKanzi是的,'$ .ajax'有一个'complete'回调。 – Hamms
@Hamms谢谢。 –
请测试:'完整:函数(响应)'和这个:'setTimeout(function(){worker();},1000);' –