forked from josephj/sync-with-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomet-ajax.html
More file actions
57 lines (54 loc) · 1.38 KB
/
comet-ajax.html
File metadata and controls
57 lines (54 loc) · 1.38 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
47
48
49
50
51
52
53
54
55
56
57
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Comet</title>
<style>
iframe {
position: fixed;
right: 10px;
top: 10px;
width: 500px;
height: 500px;
}
#show {
border: solid 1px #ccc;
padding: 5px;
width: 500px;
height: 500px;
font-size: 11px;
overflow: auto;
}
</style>
</head>
<body>
<h1>Comet (XMLHttpRequest Version)</h1>
<div id="show"></div>
<script type="text/javascript" src="http://yui.yahooapis.com/3.3.0/build/yui/yui-min.js"></script>
<script type="text/javascript">
YUI().use("node-base", function (Y) {
var node = Y.one("#show");
try {
var request = new XMLHttpRequest();
} catch (e) {
alert("Browser doesn't support window.XMLHttpRequest");
}
var pos = 0;
request.onreadystatechange = function () {
if (request.readyState === 3) { // Interactive Mode
try {
var text = request.responseText;
} catch (e) {
alert("Browser doesn't support XMLHttpRequest streaming.");
return;
}
node.append("<p>" + text.substring(pos) + "</p>");
pos = text.length;
}
};
request.open("GET", "comet-ajax.php", true);
request.send(null);
});
</script>
</body>
</html>