0

AJAX の 1 つのパラメータを使用して、ローカル サーバーにポスト リクエストを送信しようとしています。郵便配達員でリクエストを実行すると、完全に正常に動作するように見えますが、AJAX で実行すると、2 つのリクエストが 1 つは 204 として、もう 1 つは 404 として送信されます。これは非常に奇妙に思えます。

<-- OPTIONS /price/current
api_1       |   --> OPTIONS /price/current 204 1ms 
api_1       |   <-- POST /price/current
api_1       |   --> POST /price/current 404 1ms -

実際の AJAX リクエストは次のとおりです。

getBtc = async()  => {
     return await fetch("http://localhost:3001/price/current",{
         method: 'POST',
         headers: {
             'Content-Type':'application/json'

         },
         body: JSON.stringify({
             'symbol':'eth'
         })
     })          
     .then(res => {
         console.log(res)
         if (res.success) {
           this.setState({ priceBTC : res.data[0].price })
         }
     })

コンソール ログには、次の情報を含む 200 応答が指定されています。

Response {type: "cors", url: "http://localhost:3001/price/btc", redirected: false, status: 200, ok: true, …}
body: (...)
bodyUsed: false
headers: Headers {}
ok: true
redirected: false
status: 200
statusText: "OK"
type: "cors"
url: "http://localhost:3001/price/btc"
__proto__: Response

理想的には、ステータス コード 200 が返されることになります。

4

1 に答える 1