如何激活两个JavaScript函数并行? [英] How to activate two JavaScript functions in parallel?

查看:107
本文介绍了如何激活两个JavaScript函数并行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以告诉我如何激活两个(或更多)的JavaScript的AJAX功能并行?

Anyone can tell me how to activate two (or more) JavaScript AJAX functions in parallel?

推荐答案

这是不可能的。 JavaScript的只能工作在一个单独的线程,并且没有办法实际上有两个并行运行的功能。你需要打一个电话,然后其他。这些回调将被称为(不一定以相同的顺序与调用方法)中,当数据已经被返回或误​​差/发生超时。只有当一个回调完成,将第二个被允许运行。

This is not possible. Javascript can only work in a single thread and there is no way to actually have two functions running in parallel. You need to make one call and then the other. The callbacks of these will be called (not necessarily in the same order with the invocation methods), when data have been returned or an error/timeout occurs. Only when one callback completes, will the second one be allowed to run.

也有注意,浏览器限制激活AJAX调用的次数。所以,如果你试图做太多的Ajax调用,人们可能会等待(阻塞所有的JavaScript code)对于其他调用来完成。

Have also in mind that browsers restrict the number of active ajax calls. So, if you try to make too many ajax calls, one might wait (blocking all javascript code) for other calls to complete.

这篇关于如何激活两个JavaScript函数并行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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