为什么没能取得并列我JQuery的阿贾克斯的要求?没能、JQuery、阿贾克斯

2023-09-10 16:43:41 作者:初戀無限好,只是挂得早

我试图让使用jQuery像这样两个并联的Ajax请求:

I am trying to make two ajax requests in parallel using jQuery like this:

    var sources = ["source1", "source2"];

    $(sources).each(function() {
      var source = this;
      $.ajax({
        async: true,
        type: "POST",
        data: {post: "data", in: "here"},
        url: "/my/url/" + source,
        success: function(data) {
          process_result(data);
        }
      });
    });

我从基本结构this问题,但我的要求还是没有被并行地。 源1需要一段时间才能完成,而且我可以在第二个请求不发,直到第一个完成在服务器上看到的。

I got the basic structure from this question, but my requests still aren't being made in parallel. "source1" takes a while to complete, and I can see on the server that the second request isn't made until the first is completed.

据我所知,我没有任何其他活动的请求,所以我不认为这是与浏览器的并行请求的最大数量的问题。我失去了别的东西吗?

As far as I can tell, I don't have any other active requests, so I don't think it's a problem with the maximum number of parallel requests for the browser. Am I missing something else here?

推荐答案

jQuery的不排队Ajax请求。如果你的确定你没有做任何其他请求最终,怎么样的服务器?也许它只有一个工人?

jQuery does not queue AJAX requests. If you're sure you're not making any other requests your end, how about the server? Maybe it only has one worker?

修改:而只是为了确保,我与启动2 AJAX POST请求,睡5秒一个PHP脚本的脚本进行了测试。他们没有排队。

EDIT: And just to make sure, I tested it with a script that launches 2 AJAX POST requests to a PHP script which sleeps for 5 seconds. They were not queued.