"添加到购物车”;按钮不'由于ReferenceError,无法工作
"Add to cart" button doesn't work because of ReferenceError
我的Magento主题中有一个"添加到购物车"按钮,我没有编辑它,但它停止了工作。这在一段时间前起到了防御作用,但不幸的是,我没有抓住出现问题的那一刻。当我按下按钮时,前端不会发生任何事情,我在控制台中看到错误"Uncaught ReferenceError:productAddToCartForm未定义"。
这是按钮HTML:
<button class="button btn-cart" title="Добавить в корзину" type="button" onClick="productAddToCartForm.submit(this)"><i class="icon-basket"></i>Добавить в корзину</button>
然而,当我查看页面源时,脚本在页面中:
<script type="text/javascript">
//<![CDATA[
var productAddToCartForm = new VarienForm('product_addtocart_form');
<?php if(Mage::getStoreConfig('buyshopconfig/options/ajax_add_to_cart')){?>
productAddToCartForm.submit = function(button, url) {
if (this.validator.validate()) {
var form = this.form;
var oldUrl = form.action;
if (url) {
form.action = url;
}
var e = null;
// Start of our new ajax code
if (!url) {
url = jQuery('#product_addtocart_form').attr('action');
}
url = url.replace("checkout/cart","ajax/index"); // New Code
var data = jQuery('#product_addtocart_form').serialize();
data += '&isAjax=1';
jQuery('#preloader .loader').fadeIn(300);
try {
jQuery.ajax( {
url : url,
dataType : 'json',
type : 'post',
data : data,
success : function(data) {
jQuery('#ajax_loader').hide();
if(data.status == 'ERROR'){
alert(data.message);
}else{
jQuery('#preloader .loader').hide();
if(jQuery('.ul_wrapper.toplinks')){
jQuery('.shoppingcart').replaceWith(data.sidebar);
}
jQuery(".shoppingcart .fadelink").bind({
mouseenter: function(e) {
jQuery(this).find(".shopping_cart_mini").stop(true, true).fadeIn(300, "linear");
},
mouseleave: function(e) {
jQuery(this).find(".shopping_cart_mini").stop(true, true).fadeOut(300, "linear");
}
});
if(jQuery('#topline .links')){
jQuery('#topline .links').replaceWith(data.toplink);
}
jQuery('#preloader .inside').html('Товар "'data.name+'" был добавлен в вашу корзину');
jQuery('#preloader .message').fadeIn(300);
setTimeout(function(){
jQuery('#preloader .message').fadeOut();
},1500)
}
}
});
} catch (e) {
}
// End of our new ajax code
this.form.action = oldUrl;
if (e) {
throw e;
}
}
}.bind(productAddToCartForm);
<?php }else { ?>
productAddToCartForm.submit = function(button, url) {
if (this.validator.validate()) {
var form = this.form;
var oldUrl = form.action;
if (url) {
form.action = url;
}
var e = null;
try {
this.form.submit();
} catch (e) {
}
this.form.action = oldUrl;
if (e) {
throw e;
}
if (button && button != 'undefined') {
button.disabled = true;
}
}
}.bind(productAddToCartForm);
<?php } ?>
productAddToCartForm.submitLight = function(button, url){
if(this.validator) {
var nv = Validation.methods;
delete Validation.methods['required-entry'];
delete Validation.methods['validate-one-required'];
delete Validation.methods['validate-one-required-by-name'];
// Remove custom datetime validators
for (var methodName in Validation.methods) {
if (methodName.match(/^validate-datetime-.*/i)) {
delete Validation.methods[methodName];
}
}
if (this.validator.validate()) {
if (url) {
this.form.action = url;
}
this.form.submit();
}
Object.extend(Validation.methods, nv);
}
}.bind(productAddToCartForm);
<?php if(!Mage::helper('lightboxes')->isActive()):?>
jQuery("a.video").click(function() {
jQuery.fancybox({
'padding' : 0,
'autoScale' : false,
'transitionIn' : 'none',
'transitionOut' : 'none',
'title' : this.title,
'width' : 680,
'height' : 495,
'href' : this.href.replace(new RegExp("watch''?v=", "i"), 'v/'),
'type' : 'swf',
'swf' : {
'wmode' : 'transparent',
'allowfullscreen' : 'true'
}
});
return false;
});
<?php endif;?>
//]]>
有人能回答这个函数的问题吗?
在线(688)
jQuery('#preloader .inside').html('Товар "'data.name+'" был добавлен в вашу корзину');
你错过了一个+
jQuery('#preloader .inside').html('Товар "' + data.name + '" был добавлен в вашу корзину');
相关文章:
- 未捕获的ReferenceError:$未定义
- ReferenceError: not defined
- ReferenceError: cordova is not defined @ng-cordova.min.js:7
- 为什么JavaScript抛出'未捕获的ReferenceError:var未定义'定义var时
- Node.js错误“;ReferenceError:全局未定义“;在从0.10.2更新到0.12.2之后
- 未捕获的ReferenceError:未定义VM1299:1(匿名函数)
- React ReferenceError:未定义文档
- ReferenceError: $firebase is not defined
- 未捕获的ReferenceError:webkitNotifications未定义
- 尝试将js函数更改为coffeescript时发生Uncaught ReferenceError
- Web用户控件中Javascript的ReferenceError
- ReferenceError: crimeID is not defined
- Rails Uncaught ReferenceError:$$未定义为升级到jquery
- 懒惰加载插件抛出Uncaught ReferenceError
- 未捕获的ReferenceError:未定义测试(函数)
- 未捕获的ReferenceError:未在单击时定义
- ReferenceError:未定义角度
- Ionic应用程序在部署后给出ReferenceError:未定义Promise
- Uncaught ReferenceError:尝试在Android网络视图中访问时未定义函数
- ReferenceError:require未在javascript中定义