Код: Выделить всё
Index
Submit
Submit
const form1 = document.querySelector("#form1")
form1.addEventListener("submit", async (e) => {
e.preventDefault()
const query1 = form1.query1.value
const formData = new FormData()
formData.append("queryl", query1)
try {
await fetch('./index.php', {
method: 'POST',
body: formData,
headers: { 'Accept': 'application/json, text/plain, */*' }
})
.then((res) => res.json())
.then((data) => {
alert(data[0])
})
}
catch(error) { console.log(error) }
const form2 = document.querySelector("#form2")
form2.addEventListener('submit', async (e) => {
e.preventDefault()
const query2 = form2.query2.value
const formData = new FormData()
formData.append("query2", query2)
try {
await fetch('./index.php', {
method: 'POST',
body: formData,
headers: { 'Accept': 'application/json, text/plain, */*' }
})
.then((res) => res.json())
.then((data) => {
alert(data)
})
}
catch(error) { console.log(error) }
})
})
exit();
Подробнее здесь: https://stackoverflow.com/questions/786 ... n-response