Answer the question
In order to leave comments, you need to log in
How to pass ajax data from a loop?
Good day. I broke my brain, I decided to ask the question all the same. In general, there is a while loop that displays messages with a unique id, of course, under it there is supposedly a link that calls the modal window
<a href="#" data-toggle="modal" data-target="#myModal">
<a class="block" href="#">sdfsdfsdf</a>
<script>$(document).ready(function() {
$('.block_one').click(function() {
alert('fgdfgdfg');
})
});</script>
Answer the question
In order to leave comments, you need to log in
You can try to set the message ID from the database for each link to delete, then when you click on the link, display a modal window, hang an id on the delete button, for example, deleteMessage.
"Delete" button in modal window
Delete links that invoke a modal window and contain an ID from the database
<a class="delete" data-toggle="modal" id="1" data-target="#exampleModalCenter">✖</a>
<a class="delete" data-toggle="modal" id="2" data-target="#exampleModalCenter">✖</a>
<a class="delete" data-toggle="modal" id="3" data-target="#exampleModalCenter">✖</a>
<a class="delete" data-toggle="modal" id="4" data-target="#exampleModalCenter">✖</a>
var delete_id;
$('.delete').click(function (event) {
delete_id = event.target.id;
});
$('#deleteMessage').click(function () {
$.ajax({
url: '/deleteMessage',
data: {delete_id: delete_id},
method: 'POST',
success: function () {
// Дальнейшие действия
}
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question