jquery实现轮询
2016-04-16 12:50
459 查看
function showUnreadNews() { $(document).ready(function() { $.ajax({ type: "POST", url: "unread_list.php", dataType: "json", success: function(data) { //alert(msg); $("#msg").append("data "+data); } }); }); } setInterval('showUnreadNews()',500);//轮询执行,500ms一次
<?php session_start(); if (empty($_POST['time'])) exit(); set_time_limit(0); //无限请求超时时间 $sae=new SaeMysql(); $sql="SELECT * , COUNT(`chat_id`) FROM `chat` WHERE `is_read` ='0' AND `to_user_id` =".$_SESSION["userid"]." GROUP BY `from_user_id` "; while (true) { usleep(500000); //0.5秒 $result=$sae->getData($sql); if($result) { $arr = array('success' => "1", 'result' => $result); echo json_encode($arr); exit; } else{ $arr = array('success' => "0", 'result' => ""); echo json_encode($arr); exit(); } }
相关文章推荐
- 用jQuery写的简单两级树形菜单
- jQuery实现的倒计时效果实例小结
- jQuery实现漂亮实用的商品图片tips提示框效果(无图片箭头+阴影)
- jQuery实现无限往下滚动效果代码
- jQuery遍历json的方法分析
- jQuery 获取元素并添加
- knockoutjs+jquery.gridgroup 实现table数据加载和行合并
- jQuery选择器大全
- JQuery中鼠标划过一级菜单,有二级菜单的就显示的处理
- jQuery遍历json的方法分析
- jQuery实现无限往下滚动效果代码
- jQuery实现漂亮实用的商品图片tips提示框效果(无图片箭头+阴影)
- jQuery实现的倒计时效果实例小结
- 十条jQuery代码片段助力Web开发效率提升
- jQuery实现下拉菜单
- jQuery
- jQuery操作radio、checkbox、select总结
- [转]jQuery-获取屏幕高度、宽度
- jquery插件
- 理解jquery的$.extend()、$.fn和$.fn.extend()