简体   繁体   中英

How to get multiple concurrent JQuery .load requests to run at the same time?

Does anyone know how to get the jQuery .load() function to work concurrently? Right now I have two .load() functions but jQuery only seems to run one at a time.

$('#div1').load(url);
$('#div2').load(url2);

I know most browsers can run 2 concurrent AJAX requests. Am I going to have to build a $.ajax() request for both of them? I'd rather not since the .load() is so much easier. :)

Thanks for your time.

UPDATE
These actually do run concurrently. I inspected FB and they both were running however the second wasn't returning anything so I "assumed" it wasn't working. After further inspection it wasn't returning anything because I was checking a session variable, which was being reset by the previous .load() request.

Thanks for all the feedback!

The code you have does run both requests concurrently/without blocking. From the jQuery site:

The async option to $.ajax() defaults to true, indicating that code execution can continue after the request is made.

.load() is just a wrapper around the low level .ajax() and uses the defaults. Use the developer tools in your browser (ie Firebug in FireFox) to view the requests are both made and do not wait for the other to complete.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM