Why my requested parameter doesn't update?

Viewed 32

I am doing a unity web request, that sends the selected bet to the server. It send the bet fine to the server but when I change the bet I get an error that says

undefined:1 0,1 ^

SyntaxError: Unexpected token , in JSON at position 1

This example is when I try to change the bet from 0.1 to 0.5 Somehow the bet doesn't update and the period changes to comma. I am 90% sure this happens because the server side code is wrong, because I tested this out in the unity editor and it was sending the correct bet everytime. I belive it is on the first lines of code so here it is:

router.get('/:bet',async (req,res) =>{
    
    const parameter = JSON.parse(req.params.bet)
    
    const BET = parameter.bet
    req.session.bet = BET
    })

1 Answers

You are trying to convert something into JSON which is not a valid json that's why it is giving parsing issue

If you actually want to submit a large js object send it by post request method req.params.something is only a standard way for doing like getting single doc from database and deleting it You should try different approach either a post method or use req.query

Related