JSFiddle - React, Tailwind, and code Playground
HTML
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.3.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/q.js/0.9.2/q.js"></script>
JavaScript
// src: https://gist.github.com/jeffcogswell/8257755
function one() {
var deferred = Q.defer();
console.log("Starting one's's ajax");
$.ajax( {
url: 'http://ip.jsontest.com/',
success: function() {
console.log('Finished with one. Ready to call next.');
deferred.resolve();
}
});
return deferred.promise;
}
function two() {
var deferred = Q.defer();
console.log("Starting two's ajax");
$.ajax( {
url: 'http://ip.jsontest.com/',
success: function() {
console.log('Finished with two. Ready to call next.');
deferred.resolve();
}
});
return deferred.promise;
}
function three() {
var deferred = Q.defer();
console.log("Starting three's ajax");
$.ajax( {
url: 'http://ip.jsontest.com/',
success: function() {
console.log('Finished with three. Ready to call next if there is one.');
deferred.resolve();
}
});
return deferred.promise;
}
one()
.then(two)
.then(three)
.done();