I'm trying to pass a variable to my modal using AJAX but it's not working.
PHP code
echo '<img src="./images/see.png" class="open-modalPropietari" data-target="#modalPropietari" data-id="' . $id . '" >';
JS code
$(document).on('click', '.open-modalPropietari', function() {
var id = $(this).data('id');
$.ajax({
type: "POST",
url: "propietaris.php",
data: {id: id},
success: function() {
$('#modalPropietari').modal('show');
}
});
});
it does execute the success (after 6-8 seconds) but it doesn't pass the variable.
I've looked at other posts on this forum but I can't find the solution.
Im pretty new at web development so I've no clue what's wrong.
imgtag when the page renders? In what way does this fail? You're not "passing a variable using AJAX" (which is an odd mix of terminology here), you're just rendering a page with a variable, sending that value back to the server, and then showing a modal (which has nothing to do with the variable). When you debug this, where does it fail?