admin管理员组文章数量:1355522
Multipart/x-mixed-replace is a MIME-type for content with multiple parts, each replacing the previous part. This can be used to implement server push / reverse ajax / et, and apparently should work at least in Firefox. To test this out, I have set up a server which produces the following output with delay between each part:
HTTP/1.1 200 OK
Content-type: multipart/x-mixed-replace; boundary=whatever
--whatever
Content-type: text/plain
tick
--whatever
Content-type: text/plain
tock
--whatever
...
On the client side, this is the JavaScript code which I run in Firefox:
var r = new XMLHttpRequest();
r.multipart = true;
r.open('GET', '/', true);
r.onreadystatechange = function () {
console.log(r.responseText.length);
};
r.send();
I expected each responseText to replace the previous one, but it seems they are actually appended together. The size of the responseText keeps increasing as the server produces more output. Is there a way to only get the latest replaced part?
Multipart/x-mixed-replace is a MIME-type for content with multiple parts, each replacing the previous part. This can be used to implement server push / reverse ajax / et, and apparently should work at least in Firefox. To test this out, I have set up a server which produces the following output with delay between each part:
HTTP/1.1 200 OK
Content-type: multipart/x-mixed-replace; boundary=whatever
--whatever
Content-type: text/plain
tick
--whatever
Content-type: text/plain
tock
--whatever
...
On the client side, this is the JavaScript code which I run in Firefox:
var r = new XMLHttpRequest();
r.multipart = true;
r.open('GET', '/', true);
r.onreadystatechange = function () {
console.log(r.responseText.length);
};
r.send();
I expected each responseText to replace the previous one, but it seems they are actually appended together. The size of the responseText keeps increasing as the server produces more output. Is there a way to only get the latest replaced part?
Share Improve this question asked Dec 2, 2013 at 2:02 BemmuBemmu 18.3k16 gold badges81 silver badges94 bronze badges2 Answers
Reset to default 4This is no longer possible, as the support was removed from Firefox. See https://bugzilla.mozilla/show_bug.cgi?id=843508
How about storing the response length after each part, and using that as the offset:
var offset = 0;
var r = new XMLHttpRequest();
r.multipart = true;
r.open('GET', '/', true);
r.onreadystatechange = function () {
var latestPart = r.responseText.substring(offset)
offset = r.responseText.length;
};
r.send();
本文标签: javascriptUsing multipartxmixedreplace with XMLHttpRequestStack Overflow
版权声明:本文标题:javascript - Using multipartx-mixed-replace with XMLHttpRequest - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744000129a2573707.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论