views:

57

answers:

2

In a script like this, 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>
A: 

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 completes.

darren
+3  A: 

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.

Jonathan Sampson
Lol... love the three word answer. +1 :)
Doug Neiner
No longer 3 words, but thanks for the up-vote, Capt'n! :)
Jonathan Sampson