Javascript 如何将传递给nodejs的查询字符串转发到通过res.render提供服务的页面?

Javascript 如何将传递给nodejs的查询字符串转发到通过res.render提供服务的页面?,javascript,ajax,node.js,Javascript,Ajax,Node.js,在nodejs文件中,我呈现了一个名为foo.html的页面。在foo.html内部,我使用ajax从查询字符串中提取变量,并相应地加载适当的xml文档。 问题是,如果我运行nodejs服务器,我们将其称为localhost,并将querystring附加到该服务器上,那么服务器将使用querystring,而不是foo.html内部的ajax调用 有没有办法将查询字符串直接转发到foo.html 在nodejs文件server.js中: app.get('/', function (req,

在nodejs文件中,我呈现了一个名为foo.html的页面。在foo.html内部,我使用ajax从查询字符串中提取变量,并相应地加载适当的xml文档。 问题是,如果我运行nodejs服务器,我们将其称为localhost,并将querystring附加到该服务器上,那么服务器将使用querystring,而不是foo.html内部的ajax调用

有没有办法将查询字符串直接转发到foo.html

在nodejs文件server.js中:

app.get('/', function (req, res) {
    var query = req.query;
    if (query) {
        if (query.screen == "page1") {
            res.render('foo.html');
        }
    }
});

我可以想出两种方法

1st way -) you can change your rendering engine and pass the query string variables as local variables to the template and store those values as variables inside a <script></script> tag

2nd way -) keep the html but don't render the file  load it and modify it to contain the same script tag with the variables, 

类似的东西应该注意到,我使用的是一个简单的readfile和send,这不是最快的解决方案,而是使用html修改的最简单的解决方案。您还可以使用流动态修改内存中的文件。您可以在以下位置找到readfile函数参考:

我对nodejs相当陌生。如果我不是静态呈现该文件,我们将其称为index.html,它有一些css和js依赖项。。。如何加载和修改它?代码示例还是链接?无论如何,我接受你的回答。
<script>
   var a=/*text-to-replace-for-A*/;
   var b=/*text-to-replace-for-B*/;
</script>
 var fs=require('fs'); //this goes in the require section

 //this goes inside your function
 fs.readFile('/etc/passwd', function (err, data) {
   if (err) throw err;
   var finalHTML=data.replace(/\/\*text-to-replace-for-A\*\//g,variableA).replace(/\/\*text-to-replace-for-B\*\//g,variableB);
   res.send(finalHTML)
 });