js轮询实现消息提醒
前端文件

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
        <title>消息提醒</title>
</head>
<body>

<div id=
"hd">

<ul class=
"panel">
   收件箱<span data-type=
"msg">0</span>
</ul>
<ul class=
"panel3">
   收件箱<span data-type=
"msg">0</span>
</ul>
</div>


<script type=
"text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script type=
"text/javascript">
<!--
//收件箱
checkbox = function(url) {
var box = $('#hd .panel');
$.getJSON(url, function(data) {
for (k in data[0]) {
if (k == 'msg') {
if (data[0][k] > 0)
box.find('[data-type=' + k + ']').show().text(data[0][k]);
else
box.find('[data-type=' + k + ']').hide();
}
}
});
setTimeout(function() {
sbs.checkbox(url)
}, 10000);
}

checkbox3 = function(url) {
var box = $('#hd .panel3');
$.getJSON(url, function(data) {
alert(data[0]['msg']);
for (k in data[0]) {
if (k == 'msg') {
if (data[0][k] > 0)
box.find('[data-type=' + k + ']').show().text(data[0][k]);
else
box.find('[data-type=' + k + ']').hide();
}
}
});
}

checkbox('server/msg_count.php');
checkbox3('server/msg_count.php');
//-->
</script>



server/msg_count.php

<?php

$msgn = array (array (
"msg" => 10) );
echo json_encode ( $msgn );


lunzi   2013-07-28 13:25:54 评论:0   阅读:739   引用:0

发表评论>>

署名发表(评论可管理,不必输入下面的姓名)

姓名:

主题:

内容: 最少15个,最长1000个字符

验证码: (如不清楚,请刷新)

Copyright@2004-2010 powered by YuLog