可以吗?标签发送 GET 请求?
我正在使用 Node.js、Express 和 EJS 构建一个网站。过去,我创建过按钮为 type="submit"
的表单。然后,我会让我的 index.js
文件执行 res.render
来提取我尝试路由到的 ejs 文件。
现在,我正在尝试从 标记路由到名为
"/jsonData"
的 ejs 文件。
我已经在我的index.js文件中添加了GET请求:
app.get('/jsonData', (req, res) => {
res.render('jsonData');
});
并且我已经在我的home.ejs文件中添加了a标签:
<li class="nav-item">
<a class="nav-link" href="/jsonData">JSON Data</a>
</li>
我的jsonData文件位于我的views文件夹中,因为我设置了 app.set('view engine ', 'ejs');
位于 index.js
文件的前面。
当我使用 node index.js
启动服务器时,我的 home.ejs 文件运行良好,但是当我单击链接转到我的 jsonData
页面时,出现错误: 无法获取/jsonData
我确信我可能做了一些明显错误的事情,但我不知道该怎么做。
先感谢您!!
I'm building a website in Node.js, Express, and EJS. In the past, I have created forms where the button is of type="submit"
. I would then have my index.js
file do a res.render
to pull up the ejs file I'm trying to route to.
Right now, I'm trying to route from an <a>
tag to an ejs file called "/jsonData"
.
I've added the GET request in my index.js file:
app.get('/jsonData', (req, res) => {
res.render('jsonData');
});
and I've added the a tag in my home.ejs file:
<li class="nav-item">
<a class="nav-link" href="/jsonData">JSON Data</a>
</li>
My jsonData file is in my views folder because I set app.set('view engine', 'ejs');
earlier in the index.js
file.
My home.ejs file runs great when I start the server using node index.js
, but when I click on the link to go to my jsonData
page, I get the error:
Cannot GET /jsonData
I'm sure I'm probably doing something obviously wrong but I don't know what to do.
Thank you in advance!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论