comet realization with ajax&php
2024-08-26 17:17:49
1.prepare front-end code, meta content-type cannot be ignored! as to the xhr, status should be 3
<!doctype html>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body> <div id="d"></div> <script type="text/javascript" src="/dwztp/Public/dwz/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
var xhr=new XMLHttpRequest(),pos=0;
xhr.onreadystatechange=function(){
if(xhr.readyState==3){
$("#d").html(xhr.responseText.substr(pos));
pos= xhr.responseText.length;
}
else{
$("#d").html(xhr.responseText);
}
};
$.ajaxSetup({cache:false});
xhr.open("get","a.php",true);
xhr.send(null);
// $.get("a.php",function(data){
// //document.write(data);
// });
</script>
</body> </html>
2.back-end, remember to to call two methods to set time limit to unlimited and cache-control to be no-cache;
<?
set_time_limit(0);
header("Cache-Control: no-cache, must-revalidate");
echo(date('Y'));
$no=0;
while (date('Y') == '2016'){
echo 'hello 2016+'.$no.'<br/>';
ob_flush();
flush();
sleep(2);
$no++;
}
?>
最新文章
- Java反射遍历数组
- MySQL wamp密码修改
- ZendStudio13 PHP调试环境快速配置
- C#手工注入辅助工具
- 【翻译十三】java-并发之饥饿与活锁
- SSH服务器拒绝密码检测
- VBA_Excel_教程:表,格
- ios数据库
- linux(centos 6)下记录所有用户的操作以及ip、时间
- [LeetCode] Longest Harmonious Subsequence 最长和谐子序列
- 抽奖大转盘 js代码
- 1_translation_1
- [ 高危 ] my网任意账户登陆
- 转:在 C# 中使用 P/Invoke 调用 Mupdf 函数库显示 PDF 文档
- Spring boot+mybatis+thymeleaf 实现登录注册,增删改查
- 命令实现linux和客户端文件上传下载
- java注解XML
- tile38 一款开源的geo 数据库
- [Maven]Maven中的一些基本概念
- 2018.09.30 bzoj4025: 二分图(线段树分治+并查集)
热门文章
- EWS code return Error : Request failed. The remote server returned an error: (403) Forbidden OR (401) Unauthorized
- Codevs1033 蚯蚓的游戏
- 【Python学习之五】高级特性1(切片、迭代、列表生成器、生成器、迭代器)
- Unity基础-发布
- W3CPLUS DEMO一些有意思的效果备份
- GoF23种设计模式之结构型模式之代理模式
- 思维水题:UVa512-Spreadsheet Tracking
- ACM Changchun 2015 J. Chip Factory
- hql的笔记
- meteor 检测运行环境,手机或者桌面