0

I have a button that links to

    <a href="/data_entry?Display=A&ts=<%=dateStamp%><%=locTimeStamp%>">A</a>

My route,

router.get('/data_entry/:Display/:ts', function(req,res){
console.log('get display');
 });

Is not being called on click. The link is being passed in the url but the page stays on the current page.

crod
  • 235
  • 3
  • 5
  • 12
  • You specified a path that should be used as `/data_entry/something/somethingelse` and tried to use is with `/data_entry?foo=something&bar=somethingelse`. – Kevin B Feb 06 '17 at 20:14

2 Answers2

3

The Display and ts is passed as variables to the request object (req) so in order to access the values the from the url they will be stores in req.query

router.get('/data_entry', function(req, res){
    // req.query will store the display and ts values
    console.log(req.query.Display);
}

With these changes your code will function as expected

0

In order to utilize that route, you need to call it like this

curl -X GET "http://localhost:3000/data_entry/A/<%=dateStamp%><%=locTimeStamp%>"

Be sure to also properly encode the URI. See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI

If you want to use query parameters instead of named parameters, you would define your route differently and then utilize the query parameters. See: http://expressjs.com/en/4x/api.html#req.query

It would look like this:

app.get('/data_entry', function (req,res){
    console.log('get display', req.query);
});
netpoetica
  • 3,375
  • 4
  • 27
  • 37