[英]TypeError: Cannot read property 'forEach' of undefined (node js, stripe, express)
[英]Node.JS/Express/Mongo: TypeError: Cannot read property 'location' of undefined
我一直在寻找解决此问题的其他解决方案,而我在其他地方看到的所有解决方案似乎都不适合我。 我有一个要提交到数据库的表单。 我正在使用node.JS,express,mongo和pug来呈现HTML。
这是我的表格:
.modal-content
form(method='POST' action='/insert' id='newReminders')
input(type='text' name='location' id='location' placeholder='location')
br
input(type='textarea' name='reminder' rows='4' id='reminder' placeholder='type your reminder here')
br
button(type='submit' id='saveButton') save
span.close-button ×
这是我的服务器端JS:
app.post('/insert', (req, res) => { var dokoEntry = { reminder: req.body.location, content: req.body.reminder }; mongo.connect(url, function (err, db) { assert.equal(null, err); db.collection('reminders').insertOne(item, (err, result) => { assert.equal(null, err); console.log('Reminder inserted'); db.close(); }) }) res.redirect('/checkLocation'); })
术语location
是浏览器中window
对象的保留属性。 当您在元素上定义id
属性时,浏览器将通过id
的值将DOM元素分配给window中的属性。
因此,例如对于元素
<input id="location" />
您创建的属性可通过以下方式访问
window.location
但是, window.location
是浏览器的只读属性。
尝试重命名该<input>
元素
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.