-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstream_jquery.html
44 lines (44 loc) · 1.5 KB
/
stream_jquery.html
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
<!DOCTYPE>
<html>
<head>
<title>Flushed ajax test</title>
<meta charset="UTF-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
</head>
<body>
<script>
var last_response_len = false;
$.ajax('stream.php', {
xhrFields: {
onprogress: function(e)
{
var this_response, response = e.currentTarget.response;
if(last_response_len === false)
{
this_response = response;
last_response_len = response.length;
} else {
this_response = response.substring(last_response_len);
last_response_len = response.length;
}
console.log(this_response);
data = $.parseJSON(this_response);
console.log(data);
$('#results').append('<br>' + data.message);
}
}
})
.done(function(data)
{
console.log('Complete response = ' + data);
$('#results').append('<br>Complete response = ' + data);
})
.fail(function(data)
{
console.log('Error: ', data);
});
console.log('Request Sent');
</script>
<div id="results" style="border:1px solid #000; padding:10px; width:300px; height:250px; overflow:auto; background:#eee;"></div>
</body>
</html>