最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Would 2 consecutive .load calls in jquery execute async? - Stack Overflow

programmeradmin2浏览0评论

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>

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>
Share Improve this question edited Oct 1, 2015 at 18:13 Francisco Noriega asked Jan 14, 2010 at 4:52 Francisco NoriegaFrancisco Noriega 14.6k11 gold badges51 silver badges72 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

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

  1. Place the second in the callback of the first.
  2. Set $.ajax({async:false})
  3. You could possibly even set these up in a queue.

The cleanest way is probably option 2.

Yes, the full call for load is:

load( url, [data], [callback] )

the third optional parameter is a callback method that will be called when the asynchronous load method pletes.

发布评论

评论列表(0)

  1. 暂无评论