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

HTTP POST request with fetch() method not allowed

Offen
#71 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
HTML
Sterne
759
Forks
592
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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);
});
`

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

Start at the fetch('/api', options) call and trace the /api request handler or route. Reproduce the 405 locally, then verify that the endpoint accepts the shown POST request and no longer rejects it with a 405 response.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript
Bereich
api, backend
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.