forked from whcyc2002/swoole_framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomet_client.html
More file actions
46 lines (46 loc) · 1.68 KB
/
Copy pathcomet_client.html
File metadata and controls
46 lines (46 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<!DOCTYPE html>
<html>
<head>
<meta http-equiv=Content-Type content="text/html;charset=utf-8">
<script src="http://su.bdimg.com/static/superplus/js/lib/jquery-1.10.2_d88366fd.js"></script>
<script>
function cometRequest() {
$.ajax({
type: "POST",
dataType: "json",
url: "http://127.0.0.1:9443",
timeout: 80000, //ajax请求超时时间80秒
data: {time: "80"}, //80秒后无论结果服务器都返回数据
success: function (data, textStatus) {
//从服务器得到数据,显示数据并继续查询
if (data.success == "1") {
$("#msg").append("<br>[有数据]" + data.text);
}
//未从服务器得到数据,继续查询
else if (data.success == "0") {
$("#msg").append("<br>[无数据]");
} else {
console.log("ErrorMessage: " + data);
}
cometRequest();
},
//Ajax请求超时,继续查询
error: function (XMLHttpRequest, textStatus, errorThrown) {
if (textStatus == "timeout") {
$("#msg").append("<br>[超时]");
cometRequest();
} else {
console.log("Server Error: " + textStatus);
}
}
});
}
$(document).ready(cometRequest);
</script>
<title></title>
</head>
<body>
信息:
<div id="msg"></div>
</body>
</html>