Im trying to make a post request with one parameter in AJAX to a local server. When I execute the request in postman it seems to work perfectly fine but when I do it with AJAX it sends over two requests one as a 204 and another one as a 404 which seems very strange:
<-- OPTIONS /price/current
api_1 | --> OPTIONS /price/current 204 1ms
api_1 | <-- POST /price/current
api_1 | --> POST /price/current 404 1ms -
The actual AJAX request is the following:
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 })
}
})
The console log specifies a 200 response with te following info:
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
Ideally I would be getting back a status code of 200