0

So I have some routes defined, they work fine. I have a text input for searching at the top, and set up the following listener:

$('#tags').keypress(function(e) {
  if (e.keyCode == 13 && document.getElementById('tags').value != '') {
      loadDrink(document.getElementById('tags').value);
  }
});

I was refactoring stuff and came across a snag. I need that search to redirect to router.get('/find/:name', function (req,res){}); How do I do this?

Thanks!

3
  • First off, this isn't Node, this is most likely the client-side (I can tell by the fact that you are using jQuery and document...). Second, how to trigger a route depends on the client-side JS routing framework you are using. So, what are you using? Commented Mar 15, 2015 at 18:37
  • Nothing currently. I was checking out Angular and some MEAN stacks, but it was a bit too much overhead for the size of my project. Trying to keep it simple. Commented Mar 15, 2015 at 18:43
  • 1
    Well, you could use $.get since you're already using jquery: api.jquery.com/jquery.get Commented Mar 15, 2015 at 18:46

1 Answer 1

1

If I've understood you right, then you wish to redirect the client to a route at find/:name defined on your server.

In that case, do something like this:

location.replace('/find/' + name)

Or this:

location.assign('/find/' + name)

replace functions more like an HTTP redirect and the current page is not saved in the history (not accessible via the back button). assign adds the next page to the history and navigates to it.

Location is a property of the Window object.

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

Comments

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.