Skip to content

Instantly share code, notes, and snippets.

@aranajhonny
Last active March 3, 2017 01:02
Show Gist options
  • Save aranajhonny/b6c2d1f6d3f20e814bf3b36bba3d921d to your computer and use it in GitHub Desktop.
Save aranajhonny/b6c2d1f6d3f20e814bf3b36bba3d921d to your computer and use it in GitHub Desktop.
fast-ajax.js
// With unfetch or isomorphic-fetch in the browser
<body>
<div>
<button id="download"> Download.</button>
</div>
</body>
<script>
const downloadLink = document.getElementById('download');
downloadLink.onclick = ajax()
function ajax() {
fetch("https://jsonplaceholder.typicode.com/posts/1")
.then(res => res.json())
.then(json => {
console.log(data);
})
.catch(e => {
console.error(e);
});
}
</script>
// node.js with unfetch or isomorphic-fetch
// ES6
import "isomorphic-fetch";
function ajax() {
fetch("https://jsonplaceholder.typicode.com/posts/1")
.then(res => res.json())
.then(json => {
console.error(data);
})
.catch(e => {
console.error(e);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment