我正在尝试从以下文本区域获取输入并将其转换为一堆关键字
<form method="POST" action ="/input" enctype="text/plain">
<p>Enter the keywords you would like first with spaces in between</p>
<textarea name ="keys1" id="editBox" rows="5" cols="5"></textarea>
<p>Enter the keywords you would like second with spaces in between</p>
<textarea name ="keys2" id="editBox" rows="5" cols="5"></textarea>
<button type="submit">Submit</button>
</form>
但是,每当我运行以下代码(见下文)时,都会出现错误TypeError:无法读取未定义的属性'keys1'。我如何解决它?我看了其他一些问题,但是它们的解决方案并没有真正起作用(或者我听不懂)。
返回错误的代码:
app.post('/input', function(req, res) {
var firstkey = req.body.keys1;
var secondkey= req.body.keys2;
var keylist1 = firstkey.split("+");
var keylist2 = secondkey.split("+");
if(keylist1.length>0 && keylist2.lenght>0){
var output = [];
for(i=0; i<keylist1.length; i++){
for(j=0; j<keylist2.length;j++){
output.push(keylist1[i]+" " + keylist2[j]);
}
}
res.send('<a href="/">Upload more</a><br>' + output.join('<br>'));
}
});