Last active
March 3, 2017 01:02
-
-
Save aranajhonny/b6c2d1f6d3f20e814bf3b36bba3d921d to your computer and use it in GitHub Desktop.
fast-ajax.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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