为什么$ .getJSON()块浏览器? [英] Why does $.getJSON() block the browser?

查看:233
本文介绍了为什么$ .getJSON()块浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,我列出了我们监测,为客户的硬件设备。还显示每行显示设备,即无论是正在运行,暂停,启动等状态。

I have a page where I list hardware devices we monitor for customers. Each row displayed also shows the status of the device i.e. whether it's running, paused, starting up etc.

要提高页面加载时间我列出的设备,但不会为他们的状态查询,直到页面呈现。这是因为一些疑问,例如通过SNMP或其他的API可能需要多达5-10秒内做出回应。因此,对于清单说,十台设备,它可能需要超过寻找一个空白页面的用户的一分钟。因此,我下面的,而不是 -

To improve page load times I list the devices but don't query for their status until the page is rendered. This is because some queries such as via SNMP or other API's can take as much as 5-10 seconds to respond. So for a list of say ten devices it could take well over a minute of the user looking at a blank page. So I do the following instead -

在设备列表页面,我有以下脚本:

On the device list page I have the following script:

$(document).ready(function () {

  var devices = $('div[name="runStatus"]');
  devices.each(function () {

    // Get device ID (I embed this using the HTML5 data-* attributes/annotations)
    var deviceId = $(this).attr("data-deviceid");
    var url = "/devmanager/status/" + deviceId;

    $.getJSON(url, function (response) {
      // Not actually important to the question...set text status, colours etc
      $('div[data-deviceid="' + deviceId + '"]').text(response);
      //...
    });
  });
});

什么我的发现是,如果我让这个脚本运行,网页上所有链接不响应。

What I'm finding is that if I allow this script to run, all links on the page become unresponsive.

我猜这是因为我有不少几乎是平行的异步请求阻塞,直到他们从服务器获取并以某种方式的UI线程被阻止吗?

I'm guessing this is because I've quite a few almost parallel async requests blocking until they get a response from the server and somehow the "UI thread" is being blocked by this?

不过,我认为这是不应该发生的与AJAX。

However I thought this wasn't supposed to happen with AJAX.

我觉得这是'堵'的行为发生在IE8,Chrome浏览器8.0和Firefox 3.6。 Chrome浏览器实际上显示了死纺纱厕所碗(我使用Windows 7)的箭头光标+仿佛页面没有完全呈现。

I find this 'blocking' behaviour to happen in IE8, Chrome 8.0 and Firefox 3.6. Chrome in fact shows the arrow cursor + spinning-toilet-bowl-of-death (I'm using Windows 7) as if the page isn't completely rendered.

我该如何解决这个问题?

How can I fix this?

推荐答案

原来,这是不是与客户端的一个问题:

Turns out this isn't a problem with the client side:

<一个href="http://stackoverflow.com/questions/4428413/would-multiple-calls-to-the-same-asp-net-mvc-action-cause-the-browser-to-block">Would多次调用同一个ASP.NET MVC的行动会导致浏览器以阻止?

<一个href="http://stackoverflow.com/questions/4428413/would-multiple-calls-to-the-same-asp-net-mvc-action-cause-the-browser-to-block/4434805#4434805">Would多次调用同一个ASP.NET MVC的行动会导致浏览器以阻止? - 答

这正在造成的ASP.NET的被设计的功能,使在同一会议上提出的多个请求进行串行化。

This was being caused by a "by-design" feature of ASP.NET where multiple requests made in the same session are serialised.

这篇关于为什么$ .getJSON()块浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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