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

HTTP POST request with fetch() method not allowed

オープン
#71 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
HTML
スター
759
フォーク
592
PR マージ指標
30日以内にマージされた PR はありません

説明

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

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript
領域
api, backend
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。