Javascript JQuery未捕获错误:无法在初始化之前调用按钮上的方法;试图调用方法';装载';
有人能解释一下这个控制台错误以及我如何修复它吗 未捕获错误:无法在初始化之前调用按钮上的方法;试图调用方法“正在加载” 当单击“添加到购物车”按钮并在chrome developer tools中查看控制台时,这就是发生此问题的页面: 购物车按钮:Javascript JQuery未捕获错误:无法在初始化之前调用按钮上的方法;试图调用方法';装载';,javascript,jquery,twitter-bootstrap,Javascript,Jquery,Twitter Bootstrap,有人能解释一下这个控制台错误以及我如何修复它吗 未捕获错误:无法在初始化之前调用按钮上的方法;试图调用方法“正在加载” 当单击“添加到购物车”按钮并在chrome developer tools中查看控制台时,这就是发生此问题的页面: 购物车按钮: <button type="button" id="button-cart" data-loading-text="Loading..." class="btn btn-outline-inverse">Add to Cart</
<button type="button" id="button-cart" data-loading-text="Loading..." class="btn btn-outline-inverse">Add to Cart</button>
添加到购物车
Javascript:
<script type="text/javascript"><!--
$('#button-cart').on('click', function() {
$.ajax({
url: 'index.php?route=checkout/cart/add',
type: 'post',
data: $('#product input[type=\'text\'], #product input[type=\'hidden\'], #product input[type=\'radio\']:checked, #product input[type=\'checkbox\']:checked, #product select, #product textarea'),
dataType: 'json',
beforeSend: function() {
$('#button-cart').button('loading');
},
complete: function() {
$('#button-cart').button('reset');
},
success: function(json) {
$('.alert, .text-danger').remove();
$('.form-group').removeClass('has-error');
if (json['error']) {
if (json['error']['option']) {
for (i in json['error']['option']) {
var element = $('#input-option' + i.replace('_', '-'));
if (element.parent().hasClass('input-group')) {
element.parent().after('<div class="text-danger">' + json['error']['option'][i] + '</div>');
} else {
element.after('<div class="text-danger">' + json['error']['option'][i] + '</div>');
}
}
}
if (json['error']['recurring']) {
$('select[name=\'recurring_id\']').after('<div class="text-danger">' + json['error']['recurring'] + '</div>');
}
// Highlight any found errors
$('.text-danger').parent().addClass('has-error');
}
if (json['success']) {
$('#notification').html('<div class="alert alert-success">' + json['success'] + '<button type="button" class="close" data-dismiss="alert">×</button></div>');
$('#cart-total').html(json['total']);
$('html, body').animate({ scrollTop: 0 }, 'slow');
$('#cart > ul').load('index.php?route=common/cart/info ul li');
}
}
});
});
//--></script>
我已经读到,我应该在所有jquery和jquery插件js之后重新排序脚本以加载boostrap js来解决错误,但这并没有解决问题。尝试在beforeSend事件触发之前将按钮车初始化为按钮
$('#button-cart').button().on('click', function() {
对我来说,它是通过将jquery-ui.min.js文件放在bootstrap.js之前修复的 若在bootstrap.js之后调用了jquery ui文件,只需在收到错误的页面上单击ctrl+u,并签入
部分
这可能是错误的原因
在调用bootstrap.js之前放置jquery ui将解决此问题。请显示您的代码您是否尝试过按照人们的建议对脚本重新排序?我确实尝试过对脚本重新排序,但没有解决这一问题。如果你看看这一部分,你会看到订单。引导是在jquery和jquery插件之后加载的