Express:如何将请求响应发送到同一页面

时间:2018-06-27 17:57:37

标签: node.js ajax express

我正在尝试从请求获得响应后将请求响应发送到home.ejs。我想在请求到达服务器时在客户端显示加载程序,并且在请求完成时需要删除加载程序。所以为此,我需要在同一页面上将请求响应发送到客户端,即从我发送后请求的位置的home.ejs。怎么办

app.js

app.post("/home", function(req, res){
    var snapshotname= req.body.snapshotname;
    data={"indices":"a","b","c"};
    url="url";
    method="POST";
    request.post({

        url: url,
        body: JSON.stringify(data),
        headers: {
            'content-type': 'application/json'    
        }
    }, function(err, resp, body) {
        if(err) {
            console.log(err);
        }

        res.render('home');
    })
})

home.ejs

<form action="/home" method="POST">
<input type="text" name="snapshotname" >
<button type="submit">Build</button>

0 个答案:

没有答案
相关问题