在jquery中连续2次.load调用会执行异步吗? [英] Would 2 consecutive .load calls in jquery execute async?

查看:200
本文介绍了在jquery中连续2次.load调用会执行异步吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在如下的脚本中,是否会异步或一个接一个地调用 load 函数?

In a script like the following, would the load functions be called in asynchronously or one after another?

<script language="javascript" type="text/javascript">

    $(document).ready(function () {

          $("#TheLink").click(){        
                $("#PlaceToUpdate1").load("/Controller/Method/View1");
                $("#PlaceToUpdat2").load("/Controller/Method/View2");

          }

        });
    }); 
</script>


推荐答案

默认情况下是异步的。如果你需要它们一个接一个,你可以做一些事情:

Asynchronously, by default. If you need them to be one-after-the-other, you can do a few things:


  1. 将第二个放在回调中第一个。

  2. 设置 $ .ajax({async:false})

  3. 你甚至可能将它们排成队列。

最干净的方法可能是选项2.

The cleanest way is probably option 2.

这篇关于在jquery中连续2次.load调用会执行异步吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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