Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Opencart 1.5.4 addToCart()第一次页面显示函数不工作时_Php_Javascript_Opencart - Fatal编程技术网

Php Opencart 1.5.4 addToCart()第一次页面显示函数不工作时

Php Opencart 1.5.4 addToCart()第一次页面显示函数不工作时,php,javascript,opencart,Php,Javascript,Opencart,我目前正在OpenCart 1.5.4中从事一个项目。我轻轻地把车移到另一个分区,没有任何问题。事情发生在新电脑上,当他们第一次进入网站时,客户不可能将产品添加到购物车中。如果他们进入另一个页面,然后返回,它就可以正常工作。javascript文件已正确加载,没有任何问题 希望这个解释能很好地解释问题或bug 提前谢谢 JAVASCRIPT function addToCart(product_id, quantity) { quantity = typeof(quantity) !=

我目前正在OpenCart 1.5.4中从事一个项目。我轻轻地把车移到另一个分区,没有任何问题。事情发生在新电脑上,当他们第一次进入网站时,客户不可能将产品添加到购物车中。如果他们进入另一个页面,然后返回,它就可以正常工作。javascript文件已正确加载,没有任何问题

希望这个解释能很好地解释问题或bug

提前谢谢

JAVASCRIPT

function addToCart(product_id, quantity) {
    quantity = typeof(quantity) != 'undefined' ? quantity : 1;

    $.ajax({
        url: 'index.php?route=checkout/cart/add',
        type: 'post',
        data: 'product_id=' + product_id + '&quantity=' + quantity,
        dataType: 'json',
        success: function(json) {
            $('.success, .warning, .attention, .information, .error').remove();

            if (json['redirect']) {
                location = json['redirect'];
            }

            if (json['success']) {
                //$('#notification').html('<div class="success" style="display: none;">' + json['success'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');

                $('.success').fadeIn('slow');
                try {
                    $('#cart-total').html(json['total']);
                }
                catch(err) {
                    console.log(err.message());
                }

                $('html, body').animate({ scrollTop: 0 }, 'slow');

                $(".heading").animate({backgroundColor: "#FFFFFF"}, 'slow');

                $(".cart_arrow").attr("style", "display: block;");

                $(".heading").animate({backgroundColor: "#585858"}, 'slow');

            }   
        }
    });
}
函数addToCart(产品标识、数量){
数量=类型(数量)!=“未定义”?数量:1;
$.ajax({
url:'index.php?route=checkout/cart/add',
键入:“post”,
数据:“产品id=”+产品id+”&数量=”+数量,
数据类型:“json”,
成功:函数(json){
$('.success、.warning、.attention、.information、.error').remove();
if(json['redirect']){
location=json['redirect'];
}
if(json['success']){
//$('#notification').html(''+json['success']+'');
$('success').fadeIn('slow');
试一试{
$('#购物车总数').html(json['total']);
}
捕捉(错误){
console.log(err.message());
}
$('html,body')。动画({scrollTop:0},'slow');
$(“.heading”).animate({backgroundColor:“#FFFFFF”},'slow');
$(“.cart_arrow”).attr(“样式”,“显示:块;”);
$(“.heading”).animate({backgroundColor:{585858},'slow');
}   
}
});
}
更改

url: 'index.php?route=checkout/cart/add',


找到了问题的原因。当安装了Open Cart并且即将选择域时,您可以选择www或非www。这取决于您选择的一个域,另一个域不起作用。 所以这个问题的解决方案是将非www地址重定向到www地址

RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^(.*) http://www.domain.com/$1 [R=301,L]

RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
重定向必须在基础之上/


谢谢,我希望这对以后需要这种支持的人有所帮助

谢谢你的回答,但这并不是问题的真正原因,最近发现了问题,我在htaccess文件中加入了非www域地址
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^(.*) http://www.domain.com/$1 [R=301,L]

RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]