JSFiddle - React, Tailwind, and code Playground
HTML
<button class="test-me">
Test me!
</button>
JavaScript
function fetchPost(id) {
id = id || 66;
var jQueryPromise = $.ajax({
'url': 'https://jsonplaceholder.typicode.com/posts/' + id
});
return Promise.resolve(jQueryPromise);
}
var postIds = [ 2, 4, 7, 42 ];
$('.test-me').on('click.test-me', function() {
Promise.all(postIds.map(fetchPost)).then(function(results) {
alert(JSON.stringify(results));
});
});