Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP POST request with fetch() method not allowed #71

Open
irimina opened this issue Aug 5, 2023 · 0 comments
Open

HTTP POST request with fetch() method not allowed #71

irimina opened this issue Aug 5, 2023 · 0 comments

Comments

@irimina
Copy link

irimina commented Aug 5, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant