JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
JavaScript
$.support.cors = true;
//ajax commands
var loadYahooCommand = $.ajax({
type: 'GET',
url: 'https://www.yahoo.com/',
});
var loadGoogleCommand = $.ajax({
type: 'GET',
url: 'https://www.google.com'
});
/*
register call backs. you can register as many as you want per ajax command. they will get executed in the order you registered them
*/
//load yahoo command registration
loadYahooCommand.then(function (data) {
console.log({
msg: 'yahoo succeeded 1',
data: data
});
});
loadYahooCommand.then(function (data) {
console.log({
msg: 'yahoo succeeded 2',
data: data
});
});
//load google command registration
loadGoogleCommand.then(function (data) {// this gets executed once the ajax call finished
console.log({
msg: 'google succeeded 1',
data: data
});
});
loadGoogleCommand.then(function (data) {
console.log({
msg: 'yahoogoogle succeeded 2',
data: data
});
});
var allCommandsSucceeded = function (data) {
console.log({
msg: 'all succeeded',
data: data,
})
}
//wait for both ajax commands to finish
$.when(loadYahooCommand, loadGoogleCommand).then(allCommandsSucceeded);