我尝试使用我在www.example.com中定义为const的变量app.post,这样当用户在表单中提交输入时,我将接收并存储它。但当我尝试再次将变量发送给用户以让用户检查app.post中的完整信息时,它显示变量未定义。
我错过了什么在这里?请看我的代码下面
app.get('/',function(request,response){
response.sendFile(__dirname+"/CreatingService.html")
})
});
app.post('/CreatingService', (req, res) =>{
const RecID = req.body.arg1;
const assetno = req.body.arg2;
const space = req.body.arg3;
const pdate = req.body.arg4;
const dist = req.body.arg5;
const state = req.body.arg6;
const status = req.body.arg7;
const first = req.body.arg8;
const middle = req.body.arg9;
const last = req.body.arg10;
const id = req.body.arg11;
/*....some code.....*/
res.sendFile(__dirname+"/desktop2-24.html");
})
我在vs控制台中得到如下响应
{
flg: 0,
st: 200,
data: {
response: {
RecID: '888',
AssetNo: 1234,
AssetSpace: 1000,
AssetDate: '8/8',
AssetDist: 'narjes',
AssetState: 'altaeawun',
AssetStatus: 'valid',
F_owner: 'bushra',
M_owner: 'mohammed',
L_owner: 'almansour',
OwnerID: '******1010'
}
}
}
这个app.post我用来把数据发送回用户
app.post('/desktop2-24', (req, res1) =>{
const obj = JSON.parse(JSON.stringify(res3));
res1.render("readAsset",{assetno: obj.data.response.AssetNo })
/*...some code...*/
})
.catch (err =>{
console.log(err)
})
})
})
app.listen(3000);
这是我用来发送数据的ejs文件
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charsey="utf-8">
<title> Read deed info</title>
</head>
<body>
<p>assetno: <%= assetno %></p>
</body>
</html>
1条答案
按热度按时间kb5ga3dv1#
所以基本上我所要做的就是在第二个www.example.com中用空值定义变量app.post