Ajax长轮询
HTML code:
<script type="text/javascript">
<!--
var time = 0;
var http_request=null;
function HttpRequest(){
if (window.ActiveXObject){
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}else if (window.XMLHttpRequest){
http_request = new XMLHttpRequest();
}
return http_request;
}
HttpRequest();
function autoSend(timestamp){
url = 'http://www.me.c/comet/back.php';
http_request.open('GET', url, false);
//http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
http_request.send('timestamp='+ timestamp +'&num='+Math.random());
// http_request.onreadystatuschange = CallBack;
var data = http_request.responseText;
var json = eval('('+ data +')');
alert(json.timestamp);
document.getElementById('content').innerHTML += '<div>'+json.msg +'</div>'
autoSend(json.timestamp);
}
function send(){
var msg = document.getElementById('msg').value;
var url = 'http://www.me.c/comet/back.php';
http_request.open('POST', url, false);
http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
http_request.send('msg='+msg+'&num='+Math.random()
相关问答:
想知道怎么在DW中运行Ajax
我运行的文件报这个错..
Warning: Unknown: failed to open stream: No such file or directory in Unknown on line 0
Fatal error: Unknown: Failed opening requir ......
<div id="div6" runat="server" style= "height:auto;width:auto; text-align: left;">
& ......
http://localhost:8080/xx/zz.do 显示 out的 xml 数据
xml.open("GET",arguments[0],true);// arguments[0]是 /xx/zz.do
xml.send();
alert(arguments[0]);//这边有
x ......
JScript code:
var xmlHttp;
function creatReq() // 创建xmlhttprequest,ajax开始
{
if(window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest();
}
else if(window ......
javascript代码如下:
$(document).ready(function() {
$("#btn2").click(function() {
$.aja ......