Created
June 11, 2020 13:28
-
-
Save bastienapp/547363409ce4fd78d430384ae8215810 to your computer and use it in GitHub Desktop.
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
<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