Answer the question
In order to leave comments, you need to log in
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>
(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 questionAsk a Question
731 491 924 answers to any question