I have this problem:
The user clicks on a button A, then something gets created with an ajax call. The call returns some data.
Later, the user (enteres some text into an input and) will click on button B. This will start another ajax call. Now, this one needs the returned data from the first request.
This is no problem when the first call is fast enough. However, I have to assume that it could take a while, so when the user clicks on button B the first call may not be completed.
I don't want to disable button B as long as the first lasts. The user should click on button B even if the first ajax call has not yet completed. So it seems that I need to chain/queue the calls somehow.
How could I do this? And how could this be done with a longer sequence of calls. And is there a name for this scenario, is there already a pattern for it? Or am I just blind?
Rudimentary sample code:
$('button.a').click(function () {
$.post('some/url/for/action/a', {})
.done(function (returnedData) {
})
});
$('button.b').click(function () {
// now I need something from returnedData, which may not be available yet
$.post('some/url/for/action/b', {something: returnedData.something})
.done(function () {
})
});
Note: the final aim is to speed up the process to improve UX.
(Feel free to improve the title of the question. I couln't express that better.)