bharath
bharath

Reputation: 885

unable to receive data sent with get request in node server

I am sending a data along with $http.get request like below to node server.

$http.get("/deletebookData",{pathsrc : "a"}).success(function (result) {}); 

on node js i am not able to receive the {pathsrc : "a"} sent in get request.

app.get("/deletebookData", function (req, response) {
      console.log(req.body);
}); 

only empty json is printed in console

Upvotes: 0

Views: 234

Answers (1)

akn
akn

Reputation: 3722

You are not sending the data. Check the $http.get documentation.

If you want to include params in your request use:

$http({
  url: '/deletebookData',
  method: 'GET'
  params: {pathsrc : "a"}
})
.then(function(){..});

Or:

$http.get('/deletebookData',{params: {pathsrc :'a'}}).then(function(){..});

Or build your url manualy:

$http.get("/deletebookData?pathsrc=a").then(function(){..})

(Also, please note that since angular 1.4 .success() is deprecated. Use .then() instead)

Upvotes: 1

Related Questions