JSFiddle - React, Tailwind, and code Playground
by klarstil
HTML
<button class="test-me">
Test me
</button>
JavaScript
function fetchPost(id) {
id = id || 1;
return Promise.resolve($.ajax({
'url': 'https://jsonplaceholder.typicode.com/posts/' + id
}));
}
function fetchAuthor(id) {
if(!id) {
return Promise.reject(new Error("ID is mandatory"));
}
return Promise.resolve($.ajax({
'url': 'https://jsonplaceholder.typicode.com/posts/' + id
}));
}
$('.test-me').on('click.test-me', function() {
fetchPost(1).then(function(response) {
alert(JSON.stringify(response));
});
});