Home > Software engineering >  It looks like this code that try to GET request the value that send become blank
It looks like this code that try to GET request the value that send become blank

Time:12-30

  const po_orders = ref([]);
      onMounted(async () => {
        const res = await axios.get("http://127.0.0.1:4914/server/po_order",{
              customername : 'ALEX',
          });
        po_orders.value = res.data;
        console.log(res);
      });

The below is ht code in the back end side

app.get('/server/po_order',(request,response)=>{
    database.collection("po_order").find({customername : request.body['customername']}).toArray((error,result)=>{
        if(error){
            console.log(error);
        }
        response.send(result);
    })
  })

The output result show of the document that not have "customername" if I change this line in backend

database.collection("po_order").find({customername : request.body['customername']})

by specific value like

database.collection("po_order").find({customername : 'ALEX'})

the result is I expected

CodePudding user response:

First step

Change your frontend code like this:

const res = await axios.get("http://127.0.0.1:4914/server/po_order", {
  params: {
    customername : 'ALEX',
  }
})

When you are doing GET request, you should not pass the request body, but the params.

Second step

Change your backend code like this:

database.collection("po_order").find({customername : request.query['customername']})
  • Related