Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
<!DOCTYPE html>
<title>Random Ron</title>
<style type="text/css">
body {
margin: 1em auto;
max-width: 40em;
width: 88%;
<h1>Random Ron</h1>
<blockquote id="saying"></blockquote>
<button>Another quote from Ron</button>
<script crossorigin="anonymous" src=""></script>
document.querySelector('button').addEventListener('click', function(event){
// Fetch
fetch('', {
// method: 'POST',
// body: 'title=' + encodeURIComponent('My awesome new article') + '&body=' + encodeURIComponent('This is the text of my article')
}).then(function (response) {
// The API call was successful!
if (response.ok) {
return response.json();
} else {
return Promise.reject(response);
}).then(function (data) {
// This is the JSON from our response
document.querySelector('#saying').innerHTML = data;
}).catch(function (err) {
// There was an error
console.warn('Something went wrong.', err);
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment