I have basically this code:
$(document).ready(function() {
(function fillOutTable() {
$.ajax({
type: 'GET',
url: 'someUrl',
success: function(data) {
var myTable = $("#tbl1");
for(var i in data.myCollection) {
/*filling out the table*/
var str = $(
["<tr>",
"<td>", counter++, "</td>",
"<td>",
"<a href='#' class='myClass'>", data.myCollection[i].object1.name, "</a>",
"</td>",
"<td>", title1, "</td>",
"<td>", title2, "</td>",
"<td>", title3, "</td>"
"</tr>"].join("")
);
myTable.find("tbody").append(str);
myTable.find("tbody").on("click", ".myClass", function() {
$('#twitterBtstrModal').on('shown.bs.modal', function() {
alert('yes: ' + data.myCollection[i].object1.name);
}).modal();
});
}
},
error: function(jqXHR, textStatus, errorThrown) {
showNoDataMessage();
alert('Something went wrong!');
}
});
})();
There are 2 issues with this code:
When I click on a link (which is the literal for
data.myCollection[i].object1.name
) in the table, it always showms me the same datayes: data.myCollection[i].object1.name
in the alert, no matter what link I click. Although the html code in different for all of them.The more I click on the links, the more alerts I get per click: the first time I there is only one alert appears, the next time - 2 ones, the next time - 4 or something.