Creating and fetching tables and buttons within the table with the help of AJAX.
The button in the brought table does not function. I cannot see any action related to the button click on the console. What could be the reason the button is not working?
Code structure for button creation:
for (var i = 0; i < finishedExams.length; i++) {
document.getElementById('FEtemplate').innerHTML += '<tr><th>' + (i + 1) + '</th><td>' + result + '</td><td>' + title + '</td><td>' + et + '</td><td>' + humanized_time_span(date) + '</td><td><button type="button" class="btn btn-sm btn-alt-primary sendButtonData" data-qr-exam-id="' + id + '"> Send</button></div></td></tr>';
}
Code structure related for button click:
$('.sendButtonData').click(function () {
/* AJAX POST code here.. */
if (response.status == true) {
/* some codes */
} else {
/* some codes */
}
});
What have I tried?
$('body').on('click', '.sendButtonData', function(){
This code works but gets it with the ID of the first part of the table. All other buttons act as if they were working for the first row of the table.
Also, I changed the button type from "button" to "submit". Again, nothing changed.