'Can an <a> tag send a GET request?
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!!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
