使用Jade和Node.js传递动态URL

时间:2015-09-21 19:52:53

标签: node.js pug

我是Node.js的新手,我遇到了小问题。

当用户在文本框中输入Java并单击“提交”按钮时,应该转到http://localhost:3000/search/Java

我们在翡翠怎么办?

帮助高度评价。在此先感谢

extends layout
block content
.container

  p(style='white-space:pre;') You are currently logged in as #{user.username}
  br
  a(href="/logout") Logout
  br
  form(role='form', action="/search",method="get", style='max-width: 300px;')
   .form-group
      input.form-control(type='text', name="search", placeholder='enter something')
  button.btn.btn-default(type='submit') Submit



router.get('/search/:id', function(req, res){
Object.find({searchType: req.params.id},function (err, docs){
res.render('search', {search: docs, user : req.user , title : 'Search'});
});
})

2 个答案:

答案 0 :(得分:0)

你在找这个吗?

response.writeHead(302, {
  'Location': 'YourNewURL'
  //add other headers here...
});
response.end();

答案 1 :(得分:0)

通过包含javascript解决

script.
var something = function() {
window.location.href = "search/" +   
document.getElementById('search').value;
}