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

HTTP POST request with fetch() method not allowed

Abierto
#71 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
HTML
Estrellas
759
Forks
592
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.