0
Well, I’m having some doubts regarding the use of Ajax. I’m trying to get a value of a certain element <tr>
. For that I put an attribute data-
in <tr>
which is dynamically generated by PHP, but always have the return of Undefined.
My call AJAX:
$("#consulta").click(function (e) {
e.preventDefault();
$.ajax({
url: 'scripts/consulta.php',
dataType: 'html',
type: 'POST',
success: function(data) {
$("#conteudoConsulta").html(data);
$("#modalConsulta").modal("show");
}
});
});
Shape I’m using to get the value:
$("body").on("click", "tr", function () {
$("tr").addClass("select");
var id = $(this);
alert(id.closest('tr').find('td').data('cod'));
});
How could it be done in this situation?
Thank you in advance!
Thanks!! I checked the code later and noticed that it was my lack of attention. Taking advantage of the topic... There is a "better" way to do this operation?
– Yuri Freitas
For simplicity I think this is the best way.
– Sam
If the answer solved, you can mark it as right. Abs!
– Sam