admin管理员组文章数量:1332383
I'm trying to make "many" xhr request but it seems that every time it waits for the answer before making another request. It's like XHR makes a queue and always wait for the previous request to finish.
What can I do to run more simultaneous xhr request?
$('body').delegate('.download','click', function(evt){
evt.preventDefault(); // Not related
var xhr = new XMLHttpRequest();
xhr.open('GET', "proxy.php?" + this.href, true);
xhr.responseType = 'blob';
xhr.onload = function() {
if (this.status == 200) {
var blob = new Blob([this.response], {type:'audio/mp4'});
console.log(blob.size);
if(blob.size > 0){
$("<a>").attr({
download: name,
href: URL.createObjectURL(blob),
target: "_blank"
})[0].click();
}
}
};
xhr.send();
});
I'm trying to make "many" xhr request but it seems that every time it waits for the answer before making another request. It's like XHR makes a queue and always wait for the previous request to finish.
What can I do to run more simultaneous xhr request?
$('body').delegate('.download','click', function(evt){
evt.preventDefault(); // Not related
var xhr = new XMLHttpRequest();
xhr.open('GET', "proxy.php?" + this.href, true);
xhr.responseType = 'blob';
xhr.onload = function() {
if (this.status == 200) {
var blob = new Blob([this.response], {type:'audio/mp4'});
console.log(blob.size);
if(blob.size > 0){
$("<a>").attr({
download: name,
href: URL.createObjectURL(blob),
target: "_blank"
})[0].click();
}
}
};
xhr.send();
});
Share
Improve this question
edited Dec 31, 2015 at 12:16
NIMISHAN
1,2654 gold badges21 silver badges31 bronze badges
asked Dec 21, 2015 at 23:14
Gregory WullimannGregory Wullimann
5676 silver badges24 bronze badges
6
- have you tried using web worker? – prieston Commented Dec 29, 2015 at 8:25
- Yes and the same thing happens..Both worker are called together but the second XHR wait for the first XHR to finish – Gregory Wullimann Commented Dec 29, 2015 at 17:22
- How about opening new browser windows, make the requset, use post message to send the response and then close the windows? Just thoughts that may help.. not very familiar with the subject. – prieston Commented Dec 29, 2015 at 18:24
- Also second thought, use more variables or an array or object to store xhr.. the variable may be still in use untill the server respondes. – prieston Commented Dec 29, 2015 at 18:30
- have you tried it with jquery deferred?just a thought. – prajitgandhi Commented Dec 30, 2015 at 11:23
2 Answers
Reset to default 11Not a lot.
Browsers enforce a limit on:
- The number of parallel HTTP requests to a given origin
- The number of parallel HTTP requests in total (this is a larger limit)
If you split your requests between more originals you might find your constraint raised from the first to the second of the above.
Try to find something about http2, there is some info. Http2 protocol have better supporting of parallel requests.
本文标签: javascriptxmlhttprequest simultaneous request not workingStack Overflow
版权声明:本文标题:javascript - xmlhttprequest simultaneous request not working - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742294748a2448497.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论