-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathissuebook.js
More file actions
33 lines (29 loc) · 1.06 KB
/
Copy pathissuebook.js
File metadata and controls
33 lines (29 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
document.getElementById("issueBookForm").addEventListener("submit", async function(e) {
e.preventDefault();
const issueData = {
book_name: document.getElementById("book_name").value,
student_name: document.getElementById("student_name").value,
student_id: document.getElementById("student_id").value,
issue_date: document.getElementById("issue_date").value,
return_date: document.getElementById("return_date").value
};
try {
const response = await fetch("http://localhost:5000/issue-book", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(issueData)
});
const result = await response.json();
if (response.ok) {
alert("Book issued successfully!");
this.reset();
} else {
alert("Error: " + (result.message || "Failed to issue book"));
}
} catch (error) {
console.error("Error:", error);
alert("Network error");
}
});