Hi I am loading a table with JSON data created through Gson from database. The script is:
$(document).ready(function(){
$.ajax({
url:'GetProductList',
method:'post',
dataType:'json',
success: function(response) {
$(response).each(function(index,element){
$("#producttbl").append('<tr class="data-row"><td class="td-id">'+element.id+'</td><td class="td-product">'+element.product+'</td><td class="td- type">'+element.type+'</td><td class="td-quantity">'+element.quantity+'</td><td class="td-price">'+element.price+'</td><td class="td-date">'+element.date+'</td><td class="td-date"><input type="button" value="Buy" class="buy btn-primary" onclick="postData();"> </td> </tr>');
});
},
error: function(response){
alert('Error occured Could not load Data')
}
});
});
After loading this data I want to get the data in rows with class data-row
on a button click
event for which I have this script:
function postData()
{
var txtname = $(this).closest(".data-row").find('.td-product').text();
alert(txtname);
}
I am calling this function on onClick
event but it gives me nothing.
Please suggest me how do I get data of the rows on click.