I have a list of users echoed on my page using a PHP loop. When I click each user's name, a Bootsrap Modal pops up and display further details of the user. The links look like this.
<a href="#user" data-toggle="modal" data-id="{$user['id']}">UserName</a>
As you can see, I'm passing user's ID to the Bootstrap modal so that I can use it to retrieve other information of the user by calling get_user_by_id()
in the Bootstrap Modal.
Modal Looks like this
<div class="modal fade" id="user">
<div class="modal-header">
<button class="close" data-dismiss="modal">×</button>
<h3>Modal header</h3>
</div>
<div class="modal-body">
<?php
$user = get_user_by_id($id);
?>
<input type="text" name="bookId" id="bookId" value=""/>
</div>
</div>
JS code is like this
$('#user').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget)
var id = button.data('id')
})
According to the above JS code, I have my user's ID in var id
variable.
But, ther's no way I can imagine how to use that value for the above PHP function as the argument.
Is there any possible way for that?
I have edited the question to be more unique about AJAX methods which most answers were based on AJAX
PS: I'm very new to PHP and Bootstrap.