0

In react js how to send axios GET method request with parameters to Node js and in Node js how to get these parameters.

I tried below, but not working.

React js sending

(async () => {

            const totalDonations = await axios.get(
                                  "http://localhost:3000/api/userdashboard/UserDonorList", {
                                    params: {
                                        assignEvent: props.match.params.event,
                                        userEmail: props.match.params.user
                                    }
                                  }
                                );
            console.log(totalDonations.data)
            setDonationDetailList(list => [...list,...totalDonations])
        })();

Node js reading

userRouter.get('/api/userdashboard/UserDonorList', userAuth, async (req, res) => {

  try {
    if(!req.user){
    } else {
      const donationInfo = await DonationCreate.find({ userEmail: req.body.userEmail, assignEvent: req.body.assignEvent })
      console.log('donationInfo: ', donationInfo)
      res.status(201).send(donationInfo)
    }
   }
   catch (e) {
    console.log('e: ', e)
    const errors = errorhandle(e)
    res.status(400).send(errors)
   }
});
1
  • Probably you need to use POST instead. GET doesn't have params Commented Feb 17, 2021 at 14:40

1 Answer 1

1

Use req.query to get access to all the parameter in form of Object in the req object. Example : req.query.assignEvent

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.