Skip to content

Instantly share code, notes, and snippets.

@bastienapp
Created June 11, 2020 13:28
Show Gist options
  • Save bastienapp/547363409ce4fd78d430384ae8215810 to your computer and use it in GitHub Desktop.
Save bastienapp/547363409ce4fd78d430384ae8215810 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
document.getElementById('author').addEventListener("click", () => {
fetch('/test2')
.then(function (response) {
return response.text()
}).then(function (content) {
let result = document.getElementById('result');
// Convert the HTML string into a document object
var parser = new DOMParser();
var html = parser.parseFromString(content, 'text/html');
result.append(html.getElementById('insert'));
});
});
document.getElementById('author').addEventListener("click", () => {
fetch('/authors')
.then(function (response) {
return response.json();
}).then(function (json) {
let result = document.getElementById('result');
json.forEach(author => {
let li = document.createElement('li').innerHTML = author.name;
result.append(li);
});
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment