S
S
squadbrodyaga2020-11-04 13:10:27
Node.js
squadbrodyaga, 2020-11-04 13:10:27

Is it possible to use req.query in a POST request?

Hello, I'm checking the referral link with req.query.ref, but it doesn't seem to work on POST request, or I'm doing something wrong.

This is what the address looks like in the address bar: localhost:3000/signup?ref=5fa277b302227a1c04ea9612 ,
where after ?ref= comes the _id of the user from the database.

This is how I do it in GET:

router.get('/signup', async (req, res) => {
    const человек = await User.findOne({ _id: req.query.ref })
    console.log(человек)    
})

And everything works fine, but the same code, but in the POST request returns null ,
how can I solve my problem? Thank you.

OPTIONAL:
console.log(req.query) in GET shows { ref: '5fa277b302227a1c04ea9612' },
and in POST just{}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
squadbrodyaga, 2020-11-04
@squadbrodyaga

The error was in the HTML form, I had to remove /signup in the action Now everything seems to be working. PS Thanks to Michael from the comments
<form class="signup-form" action="" method="POST">

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question