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

发布于 2025-01-05 01:47:20 字数 661 浏览 0 评论 0原文

我有几个 XHR 请求,它们由 Mootools Request 类处理。此类提供了一些选项来适当地计时请求。我在做什么:

  1. XHR:发布表单数据
  2. XHR:刷新主窗格
  3. XHR:刷新子窗格

当然,请求 2 & 3 必须等待 1 完成。因此,这些都是在 onComplete 事件处理程序中触发的。但是,Request 类提供了处理多个 XHR 请求的选项。我的问题是关于这两个:

  1. 选项link可以设置为chain,以便“链接”它们,或者,正如Moo文档所述:< /p> <块引用>

    在请求运行时进行的任何启动调用都将被链接起来,并且将在当前请求完成后立即执行,一个接一个。

  2. 选项async可以设置为false,以防止以后的请求执行。根据 Moo 文档:

    <块引用>

    如果设置为 false,请求将同步并在请求期间冻结浏览器。

除了浏览器冻结部分之外,到底有什么区别?对于请求号,我应该使用哪一个? 1?同步执行是否更好,这样我确定同时不会执行任何其他操作?那么两者都使用怎么样,这有意义吗?

I have a couple of XHR requests, which are handled by the Mootools Request class. This class offers some options to time the requests appropriately. What I'm doing:

  1. XHR: Post form data
  2. XHR: Refresh main pane
  3. XHR: Refresh subpane

Of course, requests 2 & 3 must wait before 1 is finished. So these are triggered within the onComplete event handler. However, the Request class offers options for handling multiple XHR requests. 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:

    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. According to the Moo docs:

    If set to false, the requests will be synchronous and freeze the browser during request.

Apart from the browser freezing part, what is exactly the difference? Which one should I use for request no. 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

擦肩而过的背影 2025-01-12 01:47:20

出色地。 link: chain 和 async: false 之间的区别很简单。

第一个公理 - 您正在重用您的请求实例,而不是创建一个新的实例。即使你不是,它也可以与异步一起工作。例如,如果你有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();

如果你使用链:

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();

well. the difference between link: chain and async: false is simple.

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:

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();
请爱~陌生人 2025-01-12 01:47:20

链接的请求是异步的,当一个请求结束时,它会触发第二个请求,依此类推,因此您可以有多个请求,而不会同时用所有请求干扰浏览器。

链接的请求不会冻结您的浏览器。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文