-
Notifications
You must be signed in to change notification settings - Fork 0
/
scriptsPost.js
37 lines (35 loc) · 1.37 KB
/
scriptsPost.js
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
34
35
36
37
const submitPostReq = document.getElementById("submitTextLogin")
const inputLocation = document.getElementById("userLocationInput")
const inputDate = document.getElementById("userDateInput")
const inputFoodItem = document.getElementById("userFoodItemInput")
const inputRating = document.getElementById("userRatingInput")
const statusMessage = document.getElementById("statusMessageText")
submitPostReq.addEventListener("click", async function () {
let data = {
"fooditem": inputFoodItem.value,
"rating": inputRating.value,
"location": inputLocation.value,
"date": inputDate.value,
"username": localStorage.getItem("sharedVariable")
}
const response = await fetch("http://localhost:3000/add", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
})
console.log(response)
inputFoodItem.value = ""
inputRating.value = ""
inputLocation.value = ""
inputDate.value = ""
statusMessage.innerHTML = "Successfully Submitted Post!"
// const dataJSON = await response.json()
// if (dataJSON.message == "None Found Under Those Parameters"){
// statusMessage.innerHTML = "None Found Under Those Parameters"
// }else{
// statusMessage.innerHTML = "Loading Filters!"
// }
// console.log(dataJSON)
});