我的代码:
if ($numOfMessages <> 0)
{
echo "<span class='headings_sub' id='msgcntDiv'>You have " .$numOfMessages . "</span>";
echo "<a class='red_link' href='".ADDRESS."messages.php'> unopened Messages</a>";
}
Jquery的:
<script>
$(document).ready(function() {
refresh();
});
function refresh()
{
$.get('newMessageCnt.php', function (cnt) {
$("#msgcntDiv").data('cnt', cnt);
window.setTimeout(refresh,30000);
});
}
</script>
newMessageCnt.php:
<?php
include('header_application.php');
$obj_clean->check_user(); //$obj_clean defined/initialized in header_application
echo $obj_clean->getUnopenedMessagesCount($_SESSION['user_id']);
?>
有什么建议吗? 感谢
答案 0 :(得分:2)
function refresh()
{
$.get('newMessageCnt.php', function (cnt) {
$("#msgcntDiv").html("You have "+cnt);
window.setTimeout(refresh,30000);
});
}
答案 1 :(得分:1)
function refresh()
{
$.get('newMessageCnt.php', function (cnt) {
$("#msgcntDiv").html(cnt);
window.setTimeout(refresh,30000);
});
}
请勿使用data()
,请使用html()
答案 2 :(得分:0)
您正在向元素添加数据,而不是更改其内容。尝试:
$("#msgcntDiv").text(cnt);
而不是:
$("#msgcntDiv").data('cnt', cnt);