Skip to content

Commit

Permalink
now can add books
Browse files Browse the repository at this point in the history
can totally add books
  • Loading branch information
SuperninjaXII committed Nov 12, 2024
1 parent d286fb5 commit a7665ee
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
43 changes: 43 additions & 0 deletions public/js/admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const title = document.querySelector("#title");
const description = document.querySelector("#description");
const imageLink = document.querySelector("#img-link");
const download = document.querySelector("#download");
const category1 = document.querySelector("#cartegory1");
const category2 = document.querySelector("#cartegory2");
const addbtn = document.querySelector(".add-btn");
const addBook = () => {
const data = JSON.stringify([
{
title: title.value,
description: description.value,
imageLink: imageLink.value,
download: download.value,
category1: category1.value,
category2: category2.value,
},
]);

fetch("/admin/create", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: data,
})
.then((response) => response.json())
.then((data) => {
console.log("Success:", data);
title.innerHTML = "";
description.innerHTML = "";
imageLink.innerHTML = "";
download.innerHTML = "";
category1.innerHTML = "";
category2.innerHTML = "";
alert("book added");
})
.catch((error) => {
console.error("Error:", error);
alert("error");
});
};
addbtn.addEventListener("click", addBook);
2 changes: 1 addition & 1 deletion views/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ <h1>Add Books</h1>
<button class="add-btn">Create</button>
</section>
</main>
<script src="./js/app.js"></script>
<script src="./js/admin.js"></script>
</body>
</html>

0 comments on commit a7665ee

Please sign in to comment.