$(document).ready(function() {
$("body").on("click", "a", function(event) {
event.preventDefault();
var classenlace = "." + $(this,"a").prop("class");
//var section = $(this).prop("id");
var section = this.id;
$.ajax({
url: $(this).prop("href")
}) .done(function(data) {
if (data) {
if(section == "enlace" ) {
var name = $(classenlace).data('name');
var lastname = $(classenlace).data('lastname');
}
}
});
});
});
<?php
foreach ($conection->query($result3) as $row3) {
$name = $row3['name'];
$lastname =row3['lastname'];
?>
<a href="ficha.php" id="enlace" class="enlace"
data-name = "<?php echo $name; ?>"
data-lastname = "<?php echo $lastname; ?>">
<?php echo "- ".$name." ".$lastname; ?>
</a>
<?php
}
?>
To forgive my English
This code is not working,
There are 5 names and surnames:
- John smith
- Juan Garcia
- Michel Van
- Bob Dereck Michael Jackson
Any of the 5 links always returns: John smith
Why is this happening?
</div>