Reputation: 15817
I understand that JavaScript is single threaded. If you have an AJAX call then it is added to the message queue and JavaScript deals with it when it can. Say I have a function like this:
function TestAjax
{
//AJAX asynchronous call 1
//AJAX asynchronous call 2
//AJAX asynchronous call 3
}
Say the code above adds three HTML tables to a webpage (one table added per function), then I take it that AJAX asynchronous call 3 could produce the first table even though it was added to the message queue last.
I am trying to understand if the three calls could run at the same time as they are AJAX calls were the content is generated on the server.
Upvotes: 0
Views: 67
Reputation: 3034
Yes, they can run at the same time and you could experience "staggered" results (like the 2nd one finishing before the first). It all depends on how much processing is required on the server side. If your second call is to a function that returns an empty string, but your first call queries a large database, you can expect the empty string to get returned before your DB results.
Why, specifically, are you concerned with the order in which they complete?
Upvotes: 2