Neeraj
Neeraj

Reputation: 8532

What happens if I make an async ajax call after a sync ajax call?

I was wondering what will happen if I make 2 ajax calls one after the other on different events.

Lets say, I have two buttons, on click on one , I make a blocking ajax call, which lets say returns the result after 2 minutes.

On the click of the other I make a async ajax call , which returns after an average of 1 minute.

If I click button 1 and button 2 one after the other, would both ajax calls take place, or would the second call be stopped until the first (blocked) one returns?

I feel that both will take place if the browser connection limit has not reached. Otherwise , the ajax calls will wait.

I can always try creating a simple page and testing this, but want to know , what experts here feel.

Thanks

Upvotes: 0

Views: 257

Answers (2)

Timothy Groote
Timothy Groote

Reputation: 8643

The sync (blocking) ajax call will block you from starting the async ajax call before it finishes.

it might be more interesting to look at what would happen the other way around, but then again, i don't think i've ever uncovered synchronous Ajax calls in any web application i have seen. (with good reason)

Upvotes: 2

p.matsinopoulos
p.matsinopoulos

Reputation: 7810

You will not be able to click on the 2nd button if the click on the 1st button is synchronous ajax call. The browser blocks on synchronous ajax calls that are bind to a button.

Upvotes: 2

Related Questions