CodingTrain / CodingTrain/Intro-to-Data-APIs-JS

HTTP POST request with fetch() method not allowed

Aperta
#71 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
HTML
Stelle
759
Fork
592
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Post with fetch() does not work on my localhost on both Apple and Windows.
This line of code `const response = await fetch("/api", options);` throws a 405 error saying that the method is not allowed. So, no data is sent to the server. Any ideas?
Here is the larger snippet `let lat, lon;
const button = document.getElementById("submit");
button.addEventListener("click", async (event) => {
const data = { lat, lon };
const options = {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
};
const response = await fetch("/api", options);
const json = await response.json();
console.log(json);
});
`

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.