这是我的 ejs 代码
<% var tag = [''] %>
<form action="/like" method="POST">
<% for (var i in tag){%>
Tag: <input type="text" name="likes[]" value="<%= tag[i].likes %>"/><br><br>
<button type="submit" value="accept">Send Tag</button><br><br><hr>
<%} %>
</form>
这是我的 controller.js 代码
control.post('/like', (req, res, next) => {
let tags = [req.body.likes];
console.log(tags);
iglike(tags);
next();
res.send(tags);
});
当我[]从name = "likes[]"代码中删除时,会完美地返回输入的数据。
但是在控制台日志中name = "likes[]" 返回代码。undefined
例如:喜欢 []
Input : App, Web
Output: [null] , In Console: Undefined
没有喜欢[]
Input: app, web
Output: ['app, web'] ( Stores them into single array)
我希望我的输出是
Input: app, example, thanks
Output: ['app','example','thanks']
我正在使用 EJS 视图引擎和 node-express 我app.use(express.urlencoded({extended: false}))也在我的 app.js 中添加了代码。
莫回无
动漫人物
随时随地看视频慕课网APP
相关分类