CodingTrain / CodingTrain/Intro-to-Data-APIs-JS
HTTP POST request with fetch() method not allowed
- Langage dominant
- HTML
- Étoiles
- 759
- Forks
- 592
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
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);
});
`
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript
- Domaine
- api, backend
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- À clarifier
- Accessibilité débutants
- 25/100