Skip to content

Instantly share code, notes, and snippets.

@danvega
Last active November 29, 2018 19:27
Show Gist options
  • Save danvega/4f910b3257c67859a40149827edf945e to your computer and use it in GitHub Desktop.
Save danvega/4f910b3257c67859a40149827edf945e to your computer and use it in GitHub Desktop.
Add Article Comment
/**
* I will use our REST API to add a new comment
*/
function addComment(form){
const articleID = getId();
const author = document.getElementById("author").value;
const comment = document.getElementById("comment").value;
fetch(baseApiURL + "/articles/" + articleID + "/comments", {
method: "POST",
headers: {
"Content-Type": "application/json; charset=utf-8"
},
body: JSON.stringify({postId: articleID, author: author, comment: comment})
})
.then(function(response) {
if( response.ok ){
document.location.href = baseWebURL + "read.html?id=" + articleID;
}
})
.catch((err) => console.error(err));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment