I want to post some Form data to my Server. I'm setting this element programatically and setting it's URL parameters to the action attribute but it's not taking those attributes. What am I doing wrong? Below is my code:
for(let i = 0; i < itemsDatabase.length; i++){
document.getElementById("div-section-container").innerHTML += `
<div class="div-results-container">
<h2>${itemsDatabase[i].name}</h2>
<img src = ${itemsDatabase[i].image} class="img-result">
<p>${itemsDatabase[i].desc}</p>
<form method= "POST" action= "/favorites/add/name/${itemsDatabase[i].name}/desc/${itemsDatabase[i].desc}/img/${itemsDatabase[i].image}/id/${itemsDatabase[i].id}">
<button class = "btn-favourite" type="submit">Mark As Favourite</Button>
</div>
`;
}
My server code is :
app.post("/favorites/add/name/:name/desc/:desc/img/:img/id/:id", (req, res)=>{
console.log(`Post request received`);
console.log(req.params);
})
Getting this on the Browser:
Cannot POST /favorites/add/name/blue%20nightshade/desc/A%20plant%20that%20grows%20in%20the%20quieter%20areas%20of%20Hyrule.%20At%20night,%20it%20gives%20off%20a%20soft%20glow.%20Cook%20with%20it%20to%20increase%20your%20stealth./img/https://botw-compendium.herokuapp.com/api/v2/entry/blue_nightshade/image/id/198
I'm getting a 404 not found