英文:
document.getElementByID() in Node.js using express
问题
我想知道是否可以使用express按ID获取元素。
如果不可能,我正在使用express将数据从我的网站传输到我的node.js服务器。是否可以从用户获取文本输入,然后将其应用于node.js变量?
如果不可能,我将采用WebSockets
英文:
I would like to know if it's possible to get an Element by ID using express.
If it's not possible, I'm using express to transmit data from my website to my node.js server. Is it possbile to get a text input from the user, and then apply that in a node.js variable?
If that's not possible, I'll commit to websockets
答案1
得分: 0
如果你需要实时更新,那么WebSocket是你唯一的选择(而不是每次用户输入时发送HTTP请求,这会使你的服务器负荷过重)。
然而,如果你不真正需要实时交互,你可以使用传统的表单POST(或其他)方法,并在最后使用来自表单的数据向你的Express后端发送HTTP请求。
希望这对你有帮助!
英文:
Well, if you want real-time update, then websocket is your only option (instead of sending HTTP request each time user inputs, which will flood your server).
However, if you don't really need real-time interaction, you can use old-way form POST (or any) method and send HTTP request to your express backend at the end with the data from the form.
Hope this helps!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论