我有一个带有用户输入的html,我希望将该输入传输到nodejs文档。
html代码:
sudo rpm -e --nodeps python3-3.7.2-4.fc29.x86_64(my python3 rpm package)
sudo rpm -i python3-3.7.2-4.fc29.x86_64.rpm
文件已找到
index.js
public / index.html
答案 0 :(得分:1)
您必须在节点服务器中定义一条路由
app.post('/mydata',function(req,res) {
let data = req.body.name;
console.log(name);
});`
并从您的redirect()方法向该路由发送ajax请求:
function redirect() {
const name = document.getElementById("field").value;
$.ajax({
type: "POST",
url: '/mydata',
data: {name:JSON.stringify(name)},
success: success
});
答案 1 :(得分:1)
尝试一下
<script type="text/javascript">
var field;
function onload(){
field = document.getElementById("field")
}
function redirect() {
var name = field.value;
}
</script>
<form action="stats.html" onload="onload()">
<input id="field" type="text" name="name" placeholder="Player Name...">
<input id="button" type="submit" value="SEARCH" onclick="redirect()">
</form>