Answer the question
In order to leave comments, you need to log in
Why did the “buy” button on the product on opencart stop working?
I install my layout on opencart. I am slowly changing the default template in header.tpl. Initially, the "buy" button worked, but at some point it stopped, I did not have time to notice because of what. In the console writes:
Uncaught TypeError: $.ajax is not a function
at Object.add (common.js:151)
at HTMLButtonElement.onclick (index.php?route=common/home:319)
<button type="button" onclick="cart.add('40');"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md">Купить</span></button>
$.ajax({
url: 'index.php?route=checkout/cart/add',
type: 'post',
data: 'product_id=' + product_id + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
dataType: 'json',
beforeSend: function() {
$('#cart > button').button('loading');
},
complete: function() {
$('#cart > button').button('reset');
},
success: function(json) {
$('.alert, .text-danger').remove();
if (json['redirect']) {
location = json['redirect'];
}
if (json['success']) {
$('#content').parent().before('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">×</button></div>');
// Need to set timeout otherwise it wont update the total
setTimeout(function () {
$('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>');
}, 100);
$('html, body').animate({ scrollTop: 0 }, 'slow');
$('#cart > ul').load('index.php?route=common/cart/info ul li');
}
},
error: function(xhr, ajaxOptions, thrownError) {
alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
}
});
Answer the question
In order to leave comments, you need to log in
something tells me that you don't have jQuery library connected
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question