0

I have an object, like this:

$scope.user = {name: "Jim", birthday: "1/1/90", address: "123 Easy St"}

I'm making an $http call to my server and I'd like to pass this user info. I'm trying like this:

$http({
    url: '/api/coolLookup/' + userID, 
    method: "GET",
    params: {user:$scope.user}
  }).success(function(data){
      // do stuff
  });

Within my server resource (I'm using ExpressJS/Node here) I'm trying to access the user object but cannot:

exports.coolLookup = function (req, res) {
    console.log("Here's the user")
    console.log(req.params.user)
}

req.params.user returns undefined in my console. Any idea what to do here?

1
  • Do you see the json object go out on the wire in the browser's network traffic? Commented Oct 21, 2013 at 10:55

1 Answer 1

1

In Express you should do:

console.log(req.query.user);

(NOTE: query, not params)

This will give you a string, use JSON.parse() to convert it to an object.

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

1 Comment

Ah, beauty. req.params.query correctly returns the search params so it tripped me up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.