并行XmlHttpRequests [英] parallel XmlHttpRequests

查看:53
本文介绍了并行XmlHttpRequests的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试并行运行多个xmlhttprequests以响应

按钮点击。

我想启动N个异步请求并处理响应为<他们来了
。问题是实际上没有任何请求被传输,直到前一个完成后,就好像浏览器将实际连接的数量限制为1并将我的请求放入队列。我在FF和IE上尝试了这个



这里是代码:


函数newReq(){

if(window.XMLHttpRequest)

返回新的XMLHttpRequest();

else

返回新的ActiveXObject(" Microsoft) .XMLHTTP");

}


函数查询(网址){

var req = newReq();

var url = url;

this.onres = function(){

if(req.readyState!= 4)return;

document.getElementById(''results'')。innerHTML =

document.getElementById(''results'')。innerHTML +" a more

response< ; br>" ;;

}


this.go = function go(){

req.open(" GET",url,true);

req.onreadystatechange = this.onres;

req.send(null);

}

}


d =新查询(foo1);

d.go();

e = new查询(foo2);

e.go();

f = new查询(" foo3");

f.go();

g =新查询(" foo4");

g.go();

I''m trying to run multiple xmlhttprequests in parallel in response to a
button click.
I want to launch N asynchronous requests and handle the responses as
they come. The problem is that no request is actually transmitted until
the previous one finishes, as though the browser limits the number of
actual connections to 1 and puts my requests in a queue. I tried this
on FF and IE.
Here''s the code:

function newReq() {
if (window.XMLHttpRequest)
return new XMLHttpRequest();
else
return new ActiveXObject("Microsoft.XMLHTTP");
}

function Query(url) {
var req = newReq();
var url = url;
this.onres = function () {
if (req.readyState != 4) return ;
document.getElementById(''results'').innerHTML =
document.getElementById(''results'').innerHTML + "one more
response<br>";
}

this.go = function go() {
req.open("GET", url, true);
req.onreadystatechange = this.onres;
req.send(null);
}
}

d = new Query("foo1");
d.go();
e = new Query("foo2");
e.go();
f = new Query("foo3");
f.go();
g = new Query("foo4");
g.go();

推荐答案

Assaf Lavie写道:
Assaf Lavie wrote:

我正在尝试并行运行多个xmlhttprequests以响应

按钮点击。

我想启动N个异步请求并处理响应为<他们来了
。问题是实际上没有任何请求被传输,直到前一个完成后,就好像浏览器将实际连接的数量限制为1并将我的请求放入队列。我在FF和IE上尝试了这个


I''m trying to run multiple xmlhttprequests in parallel in response to a
button click.
I want to launch N asynchronous requests and handle the responses as
they come. The problem is that no request is actually transmitted until
the previous one finishes, as though the browser limits the number of
actual connections to 1 and puts my requests in a queue. I tried this
on FF and IE.



这是对HTTP 1.1协议的限制,该协议用于防止浏览器泛滥服务器并保护网络对黑客和其他坏人一点点b / b
。限制的原因并没有经得起时间的考验,他们今天并不重要,但

浏览器仍然尊重限制,因为他们' '是协议的一部分

规格。


你可以通过修改客户端以处理2个以上来解决这个问题。

请求( http://www.ajaxperformance.com/?p=33),但这是实用的

仅适用于网内,另一种选择是使用Opera浏览器

似乎忽略了限制。同样,只适用于内部网。

您可以在这里找到问题的非常好的技术概述:
http://www.oreillynet.com/xml/blog/2...about_xhr.html


对不起,但是对于你的问题没有好的答案。


-
http://www.hunlock.com - 使用Javascript,CSS进行冥想。

This is a limit to the HTTP 1.1 protocol which is in place to prevent
the browser from flooding a server and to protect the net a little
against hackers and other bad guys. The reasons for the limit didn''t
stand the test of time, they''re not important today so much but the
browsers still respect the limits because they''re part of the protocol
specifications.

You can get around this by modifying the client to handle more than 2
requests ( http://www.ajaxperformance.com/?p=33 ), but this is practical
only for intra-nets, another option is to use the Opera browser which
seem to ignore the limits. Again, only practical for intranets.
You can find a very good technical overview of the problem here:
http://www.oreillynet.com/xml/blog/2...about_xhr.html

Sorry, but there''s no good answer for the question you have.

--
http://www.hunlock.com -- Musings in Javascript, CSS.


FA
FA


" Assaf Lavie" < as ******** @ gmail.comwrote in news:1167325992.976614.16400 @

73g2000cwn.googlegroups.com:
"Assaf Lavie" <as********@gmail.comwrote in news:1167325992.976614.16400@
73g2000cwn.googlegroups.com:

我正在尝试并行运行多个xmlhttprequests以响应

按钮点击。

我想启动N个异步请求并处理响应为
I''m trying to run multiple xmlhttprequests in parallel in response to a
button click.
I want to launch N asynchronous requests and handle the responses as
they come.

http://www.hunlock.com/blogs/ Concurrent_Ajax

http://www.hunlock.com/blogs/Concurrent_Ajax


这篇关于并行XmlHttpRequests的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆