【发布时间】:2020-08-02 22:19:18
【问题描述】:
这是我的 Index.js 文件
const ig = require('./like');
const iglike = async() => {
await ig.initialize();
await ig.login('example', 'examplepass');
await ig.liketagsprocess(***tags***);
debugger;
};
module.exports = iglike;
这是我的 controller.js(路由)
control.get('/like', (req, res) => {
res.render("like");
});
control.post('/like', (req, res, next) => {
let tags = req.body.likes;
console.log(tags);
const likeobj = require('./bin/index')(like);
res.send(likeobj.iglike);
next();
res.send(tags);
});
这是我获取数据的表单 [EJS]
<% (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>
我是一名高中生,正在使用 Node express 制作我的第一个 Web 应用程序。抱歉解释不好。
我需要做的是让表单接受来自用户的数组并将其发送到“标签”下的 Index.js。
使用此代码,我只能接受一个字符串并在控制台中打印它。
当我去 localhost/like 时
表单显示并在输入数据后在控制台中打印并在 index.js
中执行我的代码我无法将控制台中打印的数据传递给我的 index.js 文件。
我收到此错误
(node:7140) UnhandledPromiseRejectionWarning: ReferenceError: tags is not defined
感谢您的帮助!
【问题讨论】:
标签: javascript node.js express post ejs