Jump to content
  • 0

Js не видит класс который появляется при сессии php


reijii
 Share

Question

<div class="modal-body">
    <?php if (!empty($_SESSION['cart'])): ?>

    <?php else: ?>
        <p>Корзина пуста...</p>
    <?php endif; ?>

    <?php if (!empty($_SESSION['cart'])): ?>

        <table class="table">
            <thead>
            <tr>
                <th scope="col">Изображение</th>
                <th scope="col">Название</th>
                <th scope="col">Цена</th>
                <th scope="col">Количество</th>
            </tr>
            </thead>
            <tbody>
            <?php foreach ($_SESSION['cart'] as $id => $item): ?>
                <tr>
                    <td><a href="#"><img class="br-3" src="images/<?= $item['img'] ?>" alt="<?= $item['title'] ?>"></a></td>
                    <td><p><?= $item['title'] ?></p></td>
                    <td><?= $item['price'] ?></td>
                    <td>
                        <?= $id ?>
                        <a id="min-to-cart" href="?cart=minus&id=<?= $id ?>" class="min-to-cart minus-btn badge-light minus-to-cart" data-id="<?php echo $id ?>"></a>
                        <?= $item['qty'] ?>
                        <a id="plus-to-cart" href="?cart=plus&id=<?= $id ?>" class="plus-btn badge-light plus-to-cart" data-id="<?php echo $id ?>"></a>
                        <a href="#" class="delete-btn remove-from-cart badge-light" data-id="<?php echo $id ?>"></a>
                        <button type="button" class="btn delete-btn remove-from-cart" id="remove-from-cart" data-id="<?php echo $id ?>"></button>
                    </td>
                </tr>
            <?php endforeach; ?>




            <tr>
                <td colspan="4" align="right">Товаров: <span id="modal-cart-qty"><?= $_SESSION['cart.qty'] ?></span> <br> На сумму: <?= $_SESSION['cart.sum'] ?> руб.</td>
            </tr>

            </tbody>
        </table>


        <form action="telegram.php" method="POST">

            <legend>Введите имя, номер телефона и адрес:</legend>

            <div class="form-group">
                <input type="text" class="form-control" id="" name="name" placeholder="Введите имя">
            </div>

            <div class="form-group">
                <input type="text" class="form-control" id="" name="phone" placeholder="Введите телефон">
            </div>

            <div class="form-group">
                <input type="text" class="form-control" id="" name="address" placeholder="Введите адрес">
            </div>

            <div class="form-group">
                <textarea name="msg" placeholder="Ваш комментарий..."></textarea>
            </div>

            <button type="submit" class="btn btn-success">Оформить заказ</button>
            <button type="button" class="btn btn-danger" id="clear-cart">Очистить корзину</button>

        </form>
        <!--<script src="common/scripts.js"></script>-->
    <?php endif; ?>

</div>
<div class="modal-footer">
    <?php foreach ($_SESSION['cart'] as $id => $item): ?>
        <a href="#" class="delete-btn remove-from-cart badge-light" data-id="<?php echo $id ?>"></a>
    <?php endforeach; ?>
</div>

 

 

 

 

 

 

 

функция полной очистки работает, видимо потому что этот класс есть изначально, а не появляется из-за сессии

 

$('.add-to-cart').on('click', function (e){
   e.preventDefault();
   let id = $(this).data('id');

   $.ajax({
           url: 'cart.php',
           type: 'GET',
           data: {cart: 'add', id: id},
           dataType: 'json',
           success: function (res) {
                   if (res.code == 'ok') {
                           showCart(res.answer);
                   } else {
                           alert(res.answer);
                   }
           },
           error: function () {
                   alert('Error');
           }
   });
});


    $('#cart-modal .modal-cart-content .remove-from-cart').on('click', function (e){
            e.preventDefault();

            let id = $(this).data('id');

            console.log(id);


    });




$('#get-cart').on('click', function (e){
   e.preventDefault();

   $.ajax({
           url: 'cart.php',
           type: 'GET',
           data: {cart: 'show'},
           success: function (res) {
                   showCart(res);
           },
           error: function () {
                   alert('Error');
           }
   });
});

$('#cart-modal .modal-cart-content').on('click', '#clear-cart', function (){

   $.ajax({
           url: 'cart.php',
           type: 'GET',
           data: {cart: 'clear'},
           success: function (res) {
                   showCart(res);
           },
           error: function () {
                   alert('Error');
           }
   });
});
Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy