Answer the question
In order to leave comments, you need to log in
Ajax double counting or how are things like this solved?
there is a block "Similar products" dev-shop.stebnev.ru/product/buket-gartenziya-kopir...
alas, there was no functionality other than a broken ajax. Ajax itself starts counting only after the site is reloaded, but for the sake of appearance, I wrote my own jquery: the code is below!
on the main pages and where the filter is, everything goes fine, but on the page of the product itself, Ajax wakes up))) and even with a minus it starts to give a double result.
Poke on the heart and poke in any basket!
var newVariables2 = parseInt($('.favorite-header').html());
$('.add_to_wishlist').click(function(event) {
$('.favorite-header').html();
newVariables2++;
$('.favorite-header').html(newVariables2);
if ($('body').hasClass('single-product')) {
$('.favorite-header').html(newVariables2);
}
if ($('body').hasClass('slick-slider')) {
$('.favorite-header').html(newVariables2-1);
}
});
$('.remove_from_wishlist_custom').click(function(event) {
$('.favorite-header').html();
newVariables2--;
$('.favorite-header').html(newVariables2);
if ($('body').hasClass('single-product')) {
$('.favorite-header').html(newVariables2+1);
}
});
$('.add_to_cart_button').click(function(event) {
$(this).text("Добавлено");
$(this).addClass('activeBtn');
var newCount = $('.basket-top-blok').html();
count++;
$('.basket-top-blok').html(count);
if ($('body').hasClass('single-product')) {
$('.basket-top-blok').html(count-1);
}
if ($('body').hasClass('slick-slider')) {
$('.basket-top-blok').html(count-1);
}
});
Answer the question
In order to leave comments, you need to log in
No Ajax "wakes up" there, and it did not "fall asleep" either.
I'll try to assume that the described problem occurs due to the fact that the script is loaded twice on the product page:
i.e. The above code works twice.
Recalculation by Ajax does not occur. the request, apparently, is not correct:
What is wrong with it - you need to look at the target file for which the request is made.
Be that as it may, this type of task on the frontend is not worth implementing.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question