P
P
P_Alexander2018-02-09 17:12:42
JavaScript
P_Alexander, 2018-02-09 17:12:42

Why is the tag not removed?

I'm trying to implement the removal of goods from the cart by clicking on the button, ajax - ohm, but it doesn't work, tell me what's the problem!??? I 100% correctly connected all the files, both the jquery library and the js file, so I did not indicate this here.
jsp

<div>
        <c:forEach var="i" items="${requestScope.out}">
        <div class="basketProduct${i.id}">
            <p><c:out value="${i.typeProduct}"></c:out></p>
            <p><c:out value="${i.model}"></c:out></p>
            <p><c:out value="${i.smodel}"></c:out></p>
            <p><c:out value="${i.cost}"></c:out></p>
            <p>-----------------------------------------</p>
        </div>

    </div>
        <form basket="${i.id}">
            <input type="hidden" name="model" value="${i.model}"/>
            <input type="hidden" name="smodel" value="${i.smodel}"/>
            <input type="hidden" name="iduser" value="${i.idUser}">
        </form>
        <button basket="${i.id}" type="button" class="btn_delete">Удалить из корзины</button>
        </c:forEach>

The file with the ajax function,
as I understand it, I send data to the server for the product that I want to delete, the data comes to the server, I deleted it from the database and everything, and the code 200 in the console, and I don’t need to send back to the page, it should just everything will be deleted, but it does not happen!
(function($) {
    $(document).ready(function() {
        $('.btn_delete').click(function() {
            var basketID = $(this).attr('basket');
            var from = $('form[basket="' + basketID + '"]');

            var data = {};
            $(from.children()).each(function (index, input) {
                data[$(input).attr('name')] = $(input).val();
            });

            $.ajax({
                type: 'POST',
                data: data,
                url: 'basket',
                success: function(result) {
                    // $('#' + basketID).html(result);
                    console.log('elements -',  $("div.basketProduct + from"));
                    $("div.basketProduct + from").remove();
                }
            });
        });
    });
})(window.jQuery);

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