简体   繁体   English

Mootools XHR请求:同步和/或链接?

[英]Mootools XHR request: synchronous and/or chained?

I have a couple of XHR requests, which are handled by the Mootools Request class. 我有几个XHR请求,这些请求由Mootools Request类处理。 This class offers some options to time the requests appropriately. 此类提供一些选项来适当地计时请求。 What I'm doing: 我在做什么:

  1. XHR: Post form data XHR:过帐表格数据
  2. XHR: Refresh main pane XHR:刷新主窗格
  3. XHR: Refresh subpane XHR:刷新子窗格

Of course, requests 2 & 3 must wait before 1 is finished. 当然,请求2和3必须等待1完成。 So these are triggered within the onComplete event handler. 因此,这些是在onComplete事件处理程序中触发的。 However, the Request class offers options for handling multiple XHR requests. 但是,Request类提供了用于处理多个XHR请求的选项。 My question is about these two: 我的问题是关于这两个:

  1. The option link can be set to chain , in order to 'chain' them, or, as the Moo docs state: 可以将选项link设置为chain ,以“链接”它们,或者按照Moo docs的说明:

    Any calls made to start while the request is running will be chained up, and will take place as soon as the current request has finished, one after another. 在请求运行期间进行的任何开始调用都将被链接起来,并且将在当前请求完成后立即进行。

  2. The option async can be set to false , to prevent later requests from executing. 可以将选项async设置为false ,以防止以后执行请求。 According to the Moo docs: 根据Moo文​​档:

    If set to false, the requests will be synchronous and freeze the browser during request. 如果设置为false,则请求将是同步的,并在请求期间冻结浏览器。

Apart from the browser freezing part, what is exactly the difference? 除了浏览器冻结部分之外,到底有什么区别? Which one should I use for request no. 我应该使用哪个请求号。 1? 1? Is it better to do it synchronously, so I'm sure nothing else executes in the meantime? 同步执行是否更好,所以我确定在此期间没有其他执行程序吗? And how about using both, does that make any sense? 以及同时使用两者,这有意义吗?

well. 好。 the difference between link: chain and async: false is simple. link:chain和async:false之间的区别很简单。

first axiom - you are reusing your request instance and not making a new one. 第一个公理-您正在重用您的请求实例,而不是创建一个新的实例。 even if you are not, it can work with async. 即使您不是,它也可以与异步一起使用。 eg, if you have async: false , then this code: 例如,如果您有async: false ,则此代码:

new Request({async:false}).send();

// this one below will not run until the UI thread has finished
new Request({async:false}).send();

// nor will this
somefunc();

if you go with chain: 如果您使用链条:

var req = new Request({link: "chain"});

req.send();
// this won't run until the previous request has completed:
req.send();
// this will run independently of the above and may finish first as
// they are not synchronous and this is a brand new instance.
new Request().send();

The chained requests are asynchronous, when one ends it triggers the second one and so on, so you can have several requests without jamming the browser with all the requests at the same time. 链接的请求是异步的,当一个请求结束时会触发第二个请求,依此类推,因此您可以拥有多个请求,而不会同时阻塞浏览器和所有请求。

The chained requests do not freeze your browser. 链接的请求不会冻结您的浏览器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM