Skip to content

Instantly share code, notes, and snippets.

@dongsub-joung
Created December 21, 2023 06:15
Show Gist options
  • Save dongsub-joung/2f03380b2916993e8703252777247ba8 to your computer and use it in GitHub Desktop.
Save dongsub-joung/2f03380b2916993e8703252777247ba8 to your computer and use it in GitHub Desktop.
value is nohting?
function showComment(commentText) {
const comment = document.createElement("div");
comment.classList.add("comment");
const paragraph = document.createElement("p");
paragraph.textContent = commentText;
comment.appendChild(paragraph);
commentsList.appendChild(comment);
}
let response= await fetch('https://myapp-api.ngrok.dev/comment/all');
const commentsList = await response.json();
console.log(commentsList);
for(i=0; i<all_data.lenght; i++){
let body= all_data.in_body;
let frist= body.indexOf('body');
let last= body.lastIndexOf('WebKitFormBoundary');
let result_string= body.substr(first+9, last-10);
showComment(result_string);
}
document.addEventListener("DOMContentLoaded", function () {
const commentForm = document.getElementById("commentForm");
const commentInput = document.getElementById("commentInput");
const commentsList = document.getElementById("commentsList");
commentForm.addEventListener("submit", function (event) {
event.preventDefault();
if (commentInput.value.trim() !== "") {
showComment(commentInput.value);
addComment(commentInput.value);
commentInput.value = "";
}
});
async function addComment(commentText) {
await fetch('https://myapp-api.ngrok.dev/comment/add', {
method: 'POST',
body: JSON.stringify({ body: commentText })
})
.then(/* Handle response */)
.catch(/* Handle errors */);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment