Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript nodejs使用数据重定向用户_Javascript_Node.js_Templates_Redirect - Fatal编程技术网

Javascript nodejs使用数据重定向用户

Javascript nodejs使用数据重定向用户,javascript,node.js,templates,redirect,Javascript,Node.js,Templates,Redirect,客户端将通过向我的服务器发送POST请求来登录。我的服务器将对此进行检查。如果成功,我想将欢迎页面发送给客户端,但通过模板引擎将一些数据插入其中。除了重定向部分,我什么都知道了。这就是我拥有的(我使用车把作为模板引擎): 问题是它以字符串形式发送html文件,而不是重定向。这意味着用户在url中看不到任何更改,因此他们无法点击“上一步”按钮返回登录页面。我猜临时值是一个字符串 app.post("/loginAttempt",function(req, res) {

客户端将通过向我的服务器发送POST请求来登录。我的服务器将对此进行检查。如果成功,我想将欢迎页面发送给客户端,但通过模板引擎将一些数据插入其中。除了重定向部分,我什么都知道了。这就是我拥有的(我使用车把作为模板引擎):


问题是它以字符串形式发送html文件,而不是重定向。这意味着用户在url中看不到任何更改,因此他们无法点击“上一步”按钮返回登录页面。

我猜临时值是一个字符串

   app.post("/loginAttempt",function(req, res)
    {
        var username = req.body.username;
        var password = req.body.password;
            //if credentials are incorrect, data is false
            //otherwise, data is a html file as a string
            var data = await checkCredentials(username,password);
            if(data === false)
            {

                res.status(404).send("fail"); //<==
            }
            else
            {
                //not a real function, just using this to simplify code for this post
                //var temp = compileWithHandlebars("./front-end/welcome.html",{myData: data});


                res.redirect("./front-end/welcome.html",{data:myData});
            }
    });
app.post(“/loginattest”),函数(req,res)
{
var username=req.body.username;
var password=req.body.password;
//如果凭据不正确,则数据为false
//否则,数据是一个字符串形式的html文件
var数据=等待检查凭证(用户名、密码);
如果(数据===false)
{

res.status(404).send(“fail”);//您是否使用
res.render
进行了尝试?能否共享
compileWithHandlebars
方法的代码?var temp=handlebars.compile(源)(templateData);-----------源是作为字符串读取的html文件很难发布,因为它实际上是一个异步调用,所以我的真实代码在回调函数中有res.send。这不起作用。客户端仍然将html文件作为字符串接收,而不是重定向
   app.post("/loginAttempt",function(req, res)
    {
        var username = req.body.username;
        var password = req.body.password;
            //if credentials are incorrect, data is false
            //otherwise, data is a html file as a string
            var data = await checkCredentials(username,password);
            if(data === false)
            {

                res.status(404).send("fail"); //<==
            }
            else
            {
                //not a real function, just using this to simplify code for this post
                //var temp = compileWithHandlebars("./front-end/welcome.html",{myData: data});


                res.redirect("./front-end/welcome.html",{data:myData});
            }
    });