我有一个 DIV,它是从准备好的文档中的 $.get 数据填充的,然后我每 5 秒调用一次 setInterval。如果#are_friends 的html 数据与以前相同,我试图做的是setInterval $.get 的成功,但如果它不同,则再次将数据加载到#are_friends。
有没有人知道我将如何做到这一点或比我试图实施的更好的方法。
<div id="are_friends"></div>
<script type="text/javascript">
$(document).ready(function() {
$.get('<?php echo $siteUrl ?>are_friends.php?userid=<?php echo $userid; ?>', function(data) {
$("#are_friends").html(data);
});
var auto_refresh = setInterval(
function ()
{
$.ajax({
url: "<?php echo $siteUrl ?>are_friends.php?userid=<?php echo $userid; ?>",
success: function(newdata){
var oldcontent = $("#are_friends").html();
if(oldcontent != newdata) {
$("#are_friends").html(newdata);
}
}
});
}, 5000); // refresh every 5000 milliseconds
});
</script>