简体   繁体   English

更改nodejs函数中的URL?

[英]Changing the URL in function for nodejs?

I am using Express.js in my project. 我在项目中使用Express.js。 When I submit a form, a function is executed and what I would like is that at the end of the function, it changes the page from index to results. 当我提交表单时,将执行一个函数,而我希望函数结束时,它将页面从索引更改为结果。

io.on('connection', function(socket){
  socket.on('query', function(qCity,qState,qLowPrice,qHighPrice, req, res){

I want it to redirect here: 我希望它在这里重定向:

  }); // end of socket.on query function
}); // end of io.on

I've read on some posts about using middleware but still not sure it's exactly what I want. 我已经阅读了一些有关使用中间件的文章,但仍不确定这正是我想要的。

use res.redirect 使用res.redirect

io.on('connection', function(socket){
    socket.on('query', function(qCity,qState,qLowPrice,qHighPrice, req, res){
    res.redirect('http://yourdomain.com/result')

    });

您应该可以像这样在express中使用重定向:

res.redirect('your/path.html');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM