JSFiddle - React, Tailwind, and code Playground
HTML
<button id="button">Click Me</button>
JavaScript
$('#button').click(function() {
var inProgress = 0;
function handleBefore() {
inProgress++;
};
function handleComplete() {
if (!--inProgress) {
alert('All done');
}
};
$.ajax({
beforeSend: handleBefore,
complete: function () {
// whatever
handleComplete();
// whatever
},
data: {
delay: 2
},
url: '/echo/json'
});
$.ajax({
beforeSend: handleBefore,
complete: function () {
// whatever
handleComplete();
// whatever
},
data: {
delay: 2
},
url: '/echo/json'
});
$.ajax({
beforeSend: handleBefore,
complete: function () {
// whatever
handleComplete();
// whatever
},
data: {
delay: 2
},
url: '/echo/json'
});
});