Send post parameter to restify

Asked

Viewed 43 times

2

I’m trying to send parameter to nodejs with restify, but it’s always coming undefined

I’m sending it sort of like this:

$.ajax({
       url : 'http://localhost:8080/api',
       type: 'post',
       dataType: 'json',
       data: {
            ano : ano
        }    
     })

And in the Ode I’m getting like this:

server.post('/api/temp/anual', async (req, res, next) =>{

        try{
            const { ano } =  req.params
            console.log( ano )
            res.send( await db.medicao().anual( ano ) )
            next()
        }catch (error) {
            res.send(error)
            next()
        }
    })

Only the value always comes as undefined

If I try for Postman it will correct

  • I found out: I’ve changed req.params for req.body

  • Provide an answer to your own question as you discovered the answer :)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.