I have a delete button in a <td>
in a html table with an onclick()
function attached to it. How to call ajax from this function i.e. I'd like to get the values in the <tr>
and post to a URL.
<script>
function deleteRow(btn) {
var row = btn.parentNode.parentNode;
id = row.cells[0].textContent;
//call ajax, pass id as data
}
</script>
<body>
<table>
<tr>
<th>Id</th>
<th>Lastname</th>
<th>Firstname</th>
<th></th>
</tr>
<tr>
<td>122</td>
<td>Jackson</td>
<td>Evans</td>
<td><button type="button" onclick="deleteRow(this)">Delete row</button></td>
</tr>
</table>
</body>