Skip to content

Instantly share code, notes, and snippets.

@sugyan
Created September 29, 2011 09:36
Show Gist options
  • Save sugyan/1250399 to your computer and use it in GitHub Desktop.
Save sugyan/1250399 to your computer and use it in GitHub Desktop.
XDomainRequest onprogress
var http = require('http');
http.createServer(function (req, res) {
if (req.url === '/stream') {
res.writeHead(200, {
'Access-Control-Allow-Origin': '*'
});
res.write(Array(257).join(' '));
setInterval(function () {
res.write('hoge');
}, 1000);
} else {
res.writeHead(200, {
'Content-Type': 'text/html'
});
require('data-section').get('html', function (err, data) {
res.end(data);
});
}
}).listen(8888);
/* __DATA__
@@ html
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
var i = 256;
var xdr = new XDomainRequest();
xdr.open('GET', '/stream');
xdr.onprogress = function () {
var res = xdr.responseText.substring(i, xdr.responseText.length);
i += res.length;
console.log(res);
};
xdr.send();
</script>
</head>
<body>
</body>
</html>
__DATA__*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment