CodingTrain / CodingTrain/Intro-to-Data-APIs-JS
HTTP POST request with fetch() method not allowed
- 主要言語
- 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