简体   繁体   English

Node.JS / Express / Mongo:TypeError:无法读取未定义的属性“位置”

[英]Node.JS/Express/Mongo: TypeError: Cannot read property 'location' of undefined

I've gone searching for other solutions to this problem and none of the solutions I've seen elsewhere seem to work for me. 我一直在寻找解决此问题的其他解决方案,而我在其他地方看到的所有解决方案似乎都不适合我。 I have a form that I want to submit to a database. 我有一个要提交到数据库的表单。 I'm using node.JS, express, mongo, and pug to render the HTML. 我正在使用node.JS,express,mongo和pug来呈现HTML。

Here's my form: 这是我的表格:

.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 ×

And here's my server-side JS: 这是我的服务器端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'); }) 

The term location is a reserved property of The window object in browsers. 术语location是浏览器中window对象的保留属性。 When you define an id attribute on an element, the browser will assign the DOM element to a property in window by the value of id . 当您在元素上定义id属性时,浏览器将通过id的值将DOM元素分配给window中的属性。

So, for example, for the element 因此,例如对于元素

<input id="location" />

your creating a property accessible via 您创建的属性可通过以下方式访问

window.location

However, window.location is a read-only property of the browser. 但是, window.location是浏览器的只读属性。

Try renaming that <input> element 尝试重命名该<input>元素

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型错误:无法读取未定义的属性“forEach”(节点 js、stripe、express) - TypeError: Cannot read property 'forEach' of undefined (node js, stripe, express) Node.js TypeError:无法读取未定义的属性“主机” - Node.js TypeError: Cannot read property 'host' of undefined 类型错误:无法读取未定义的 Node.js 的属性 - TypeError: Cannot read property of undefined Node.js Node.js-TypeError:无法读取未定义的属性“ document” - Node.js - TypeError: Cannot read property 'document' of undefined Node.js中的TypeError:无法读取未定义的属性“ 0” - TypeError in node.js: cannot read property '0' of undefined 未捕获的类型错误:无法读取 node.js 中未定义的属性“通道” - Uncaught TypeError: Cannot read property 'channel' of undefined in node.js Node.js 抛出 TypeError:无法读取未定义的属性“testModule” - Node.js throwing TypeError: Cannot read property 'testModule' of undefined TypeError:无法读取未定义的属性“ get”(Node.js) - TypeError: Cannot read property 'get' of undefined (Node.js) TypeError:无法读取node.js中未定义的属性“名称” - TypeError: Cannot read property 'name' of undefined in node.js Node.js UnhandledPromiseRejection:TypeError:无法读取未定义的属性“ sign” - Node.js UnhandledPromiseRejection: TypeError: Cannot read property 'sign' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM