JSFiddle - React, Tailwind, and code Playground
by Matthew Day
HTML
<button>Get Dogs</button>
JavaScript
(function($) {
let app = {
getDogs: () => {
let promise = new Promise((res, rej) => {
$.ajax({
headers: {
"accept": "application/json; odata=verbose"
},
type: 'GET',
url: 'https://dog.ceo/api/breeds/image/random',
success: function(items) {
console.log(items);
res();
},
error: (error) => {
console.log(error);
rej();
}
});
});
return promise;
},
handleClick: function() {
$('button').on('click', function() {
app.getDogs();
})
},
init: function() {
app.handleClick();
},
};
$(document).ready(function() {
app.init();
})
})(window.jQuery)
// These are the characters we sanitize. Copy and paste this to test the input: ~&<>"'`,!@$%()=+{}[]/?#*^:;.-