J
J
jakiro700002021-05-10 18:14:32
AJAX
jakiro70000, 2021-05-10 18:14:32

How to display in the modal window the loading of information on the selected element in PHP?

How to load information about the selected work in a modal window via ajax?
Output of all works:

<?php
    $sql = "select * from services";
    $result=$connection->query($sql);
    foreach($result as $row){
    echo '
            <div class="services-item">
                <img src="img/services/'.$row['img_s'].'" alt="" class="services-img">
                <div class="services_text">
                    <p class="services-title">'.$row['name_s'].'</p>
                    <p class="services-subtitle">'.$row['opis_s'].'</p>
                </div>
            </div>
            ';}
?>

Modal window of the selected work:
<?php
                        $id=$_REQUEST['id'];
                        $sql='SELECT name_w, stek, site, img_w, made_by_me from works where id_w='.$id;
                        $result=$connection->query($sql);
                        foreach($result as $rows){
                            echo '

                    <div class="modal_head">
                        <div class="modal-group">
                            <h2 class="work-heading">Название:</h2>
                            <p class="work-name">'.$rows['name_w'].'</p>
                        </div>
                        <div class="modal-group">
                            <h2 class="work-heading">Стек:</h2>
                            <p class="work-stack">'.$rows['stek'].'</p>
                        </div>
                        <div class="modal-group-site">
                            <h2 class="work-heading">Сайт:</h2>
                            <a href="'.$rows['site'].'" target="_blank" class="work-site_link">Перейти</a>
                        </div>
                    </div>
                    <div class="modal_item-img">
                        <img src="img/works/'.$rows['img_w'].'" alt="" class="work-img">
                    </div>
                    <div class="modal_item">
                        <div class="modal-group-description">
                            <h2 class="work-heading by_me">Что сделано мной:</h2>
                            <ul class="work-description_list">
                                <li class="work-description_list-item">
                                    <p class="work-description">Адаптивная, кроссбраузерная верстка сайта с нуля.</p>
                                </li>
                                <li class="work-description_list-item">
                                    <p class="work-description">Сознание анимации.</p>
                                </li>
                                <li class="work-description_list-item">
                                    <p class="work-description">Сознание слайдеров.</p>
                                </li>
                                <li class="work-description_list-item">
                                    <p class="work-description">Сознание форм обратной связи и анимации.</p>
                                </li>
                            </ul>
                        </div>
                    </div>
            ';}
?>

ajax which passes the data-id of each job:
$(document).ready(function(){
    $(".open-modal-work-js").click(function () {
        var modal = $('.modal-window');
        var id = $(this).attr("data-id");
        $.post("/index.php"+id, {}, function (data) {
            modal.fadeIn();
            $('body').css({overflow:'hidden'});
        });
        return;
    });
});

Where to dig next? How to load information about the selected work in the modal window?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question