I have an EJS page in which I am presenting data in the following structure:
What is the correct way to properly send ticket.ticketNumber when the button is clicked?
Thanks in advance for any tips and advice.
Update: Through using an xhttp request I have managed to receive a req.body. I am now trying to pass a parameter to the callback function but it's undefined.
This is the EJS file (please mind the onclick method):
<%- include("partials/header.ejs") %>
<h1>Please address the following tickets according to their urgency</h1>
<div class="box">
<% openTickets.forEach(function(ticket){ %>
<div class="item">
<form class="tickets-form" action="" method="">
<p>
<span style="text-decoration: underline; font-weight: bold"
>Ticket Number:</span
>
<%= ticket.ticketNumber %>
</p>
<p>
<span style="text-decoration: underline; font-weight: bold"
>Employee Name:</span
>
<%= ticket.employeeName %>
</p>
<p>
<span style="text-decoration: underline; font-weight: bold"
>Department:</span
>
<%= ticket.departmentName %>
</p>
<p>
<span style="text-decoration: underline; font-weight: bold"
>Urgency:</span
>
<%= ticket.urgencyLevel %>
</p>
<p>
<span style="text-decoration: underline; font-weight: bold"
>Incident Description:</span
>
<%= ticket.incidentDescp %>
</p>
</form>
<button
type="Submit"
class="btn btn-primary"
onclick="resolve(ticket.ticketNumber)"
>
Resolve
</button>
</div>
<% }); %>
</div>
<script src="resolve.js"></script>
<%- include("partials/footer.ejs") %>
This is resolve.js:
function resolve(ticketNum) {
var xhttp = new XMLHttpRequest();
xhttp.open("POST", "/resolve", true);
xhttp.setRequestHeader("Content-type", "application/json");
data = {
ticketNumber: ticketNum,
};
xhttp.send(JSON.stringify(data));
}
This is the error:
Uncaught ReferenceError: ticket is not defined
at HTMLButtonElement.onclick
Any tips?