如何将.EJS文件中声明的对象导出到我的index.js

发布于 2025-02-01 19:44:58 字数 807 浏览 1 评论 0原文

我的.ejs文件中有一个脚本,脚本很简单,我只是从用户那里抓住输入数据并将其放入对象中。因此,我要做的是将此对象发送到我的index.js,在我的index.js中,我将使用来自对象的数据在名为COAP的节点模块中使用(对HTTP非常模拟),但是我真的不知道如何将我的对象表单一个.ejs文件发送到我使用的Express模块​​的index.js文件。

const btnSubmitData = document.getElementById("btnSubmitData")
btnSubmitData.addEventListener("click", () => {

    const boardIP = document.getElementById("BoardInputIP").value
    const boardMethod = document.querySelector('input[name="inlineRadioOptions"]:checked').value
    const boardFunction = document.getElementById("selectFunction").value
    const boardPoint = document.getElementById("selectPoint").value

    const inputDataBoard = {
        ipBoard: boardIP,
        methodCoapBoard: boardMethod,
        functionBoard: boardFunction, 
        pointBoard: boardPoint
    }


    })

I have a script inside of my .ejs file, the script is very simple, I'm just grabbing the input data from the user and putting inside an object. So, what I want to do is to send this object to my index.js and in my index.js I'm gonna use the data from my object to use in a node module called coap (is very simular to http), but I don't really know how to send my object form a .ejs file to my index.js file which I'm using the express module.

const btnSubmitData = document.getElementById("btnSubmitData")
btnSubmitData.addEventListener("click", () => {

    const boardIP = document.getElementById("BoardInputIP").value
    const boardMethod = document.querySelector('input[name="inlineRadioOptions"]:checked').value
    const boardFunction = document.getElementById("selectFunction").value
    const boardPoint = document.getElementById("selectPoint").value

    const inputDataBoard = {
        ipBoard: boardIP,
        methodCoapBoard: boardMethod,
        functionBoard: boardFunction, 
        pointBoard: boardPoint
    }


    })

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北城挽邺 2025-02-08 19:44:58

您不需要使用EJS显示 - 而不是index.js吗?

don't you have to use ejs to display - not index.js?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文