I'm working on a game that uses a lot of AJAX calls to update, save, edit save games, etc.
Thing is that it seems that subsequently started AJAX requests do not queue up like I want to.
For example I'm checking server side if an action is allowed, so I need a current save game. The save game is sent before, but the check request executes before the save game request finished.
So I want it so be like this:
AJAX start: Save Game
AJAX finish: Save Game
AJAX start: Check
AJAX finish: Check
AJAX start: Save Game
AJAX finish: Save Game
Currently it's more like this:
AJAX start: Save Game
AJAX start: Check
AJAX finish: Save Game
AJAX start: Save Game
AJAX finish: Check
AJAX finish: Save Game
Even though timewise the AJAX calls are triggered in correct order. They just would need to wait until the previous triggered call finished.
Is there a way to achieve this globally? Because the thing is that most calls don't know about the other requests.
Can I get this done without setInterval
calls to check if a requests finished?
UPDATE: Obviously, I didn't cleared out the actual problem. I know that this is because AJAX is async.
But I need those to stay in queue. Also at runtime I don't know about what calls are triggered at which time, because this is all user action dependend. So I can't call the check
request after the save
request, because I have no idea if the user triggered an action that need to call the check
request.
So I need a global implementation, where ajax requests always wait for their execution until every request that pre existed has finished.
So I want those calls to be async (to not freeze the UI, etc) but "sync" in regards of their execution order.