装入一张AJAX事件导致所有其他等待它处理之前,事件、AJAX

2023-09-10 20:50:02 作者:黄昏集市

我有一个处理业务数据单页的应用程序。我使用jQuery的阿贾克斯()。

在提交表单,我们加载通过AJAX请求。这里没有问题,在页面现在完全加载​​。当它完成加载,我送过,它包含了很多信息又AJAX请求 - 这是一个框,加载了一堆的业务统计。这可能需要长达15秒。在此期间,浏览器将不处理另一个AJAX请求,而在这种情况下,是一系列的导航链接,加载通过AJAX其他网页。它将开始的要求,但它似乎无法直至统计,AJAX完成其负荷加载任何东西。这甚至当我访问导航页面,仅仅是HTML如此。 (所以应该立即加载)

我不使用异步:假的。请求是这样的:

  $。阿贾克斯({
    键入:POST,
    网址:load_navigation,
    数据:passed_data,
    成功:功能(数据){
        $('#DIV对放,结果)HTML(数据)。
    }
});
 

解决方案

我唯一的想法是连接限制。 请参考:最大并行的HTTP连接在浏览器中。 我看,它可以在使用低带宽连接你被限制越强,但没有在该时间参考。 作为一个测试您可以把隐藏的 IFRAME 用GET请求,而不是职位( $。参数(passed_data))。为了让数据使用这样的:

  VAR uploadIframe = $(IFRAME);
uploadIframe.load(函数(){
    。VAR iframeBody = uploadIframe.contents()找到(身体);
    数据= iframeBody.text();
});
 
jQuery Ajax

祝你好运!

I have a single-page application that handles business data. I'm using jQuery .ajax().

On submit of a form, we load in a request via AJAX. No problem there, the "page" is now fully loaded. When it finishes loading, I send off another AJAX request that contains a lot of information - it's a box that loads a bunch of business statistics. This can take up to 15 seconds. During this time, the browser will not process another AJAX request, which in this case is a series of navigation links that load other pages through AJAX. It will start the request, but it appears to be unable to load anything until the statistics-AJAX finishes its load. This is true even when I am accessing a navigation page that is merely HTML. (so it should load instantly)

I am not using async: false. A request looks like:

$.ajax({
    type:'POST',
    url: 'load_navigation',
    data: passed_data,
    success: function(data) {
        $('#div-to-put-result').html(data);
    }
});

解决方案

The only idea I have is connection limitation. Please refer to: Max parallel http connections in a browser?. I read that it can be limited stronger when you using low bandwidth connection, but do not have reference at this time. As a test you can put hidden IFRAME with get request instead of post ($.param(passed_data)). To get data use something like:

var uploadIframe = $("IFRAME");
uploadIframe.load(function() {
    var iframeBody = uploadIframe.contents().find("body");
    data = iframeBody.text();
});

Good luck!