【问题标题】:jQuery not working on safari browser, and on chorome in MACjQuery 无法在 Safari 浏览器和 MAC 中的 chorome 上运行
【发布时间】:2018-05-11 17:31:56
【问题描述】:

我刚刚完成了一个网站,链接是 http://techuire.com/portfolio/BlotHub/

这个网站的问题是 jQuery 根本不能在 safari 浏览器上运行。 jQuery 也不适用于 MAC 中的 Chrome。

如何测试?请在 PC 中的 Chrome 上打开上述链接,然后在 MAC 或 Safari 中的 Chrome 上执行相同操作。转到组合交易并单击添加到购物车。左侧购物车不会在以后的操作系统和浏览器上更新。但将在 Windows PC 的 Chrome 上加载。

我提到我的代码以供参考。当用户单击“添加到购物车”按钮时,此代码将被执行

<script type="text/javascript">

  $(document).ready(function(){

                   $('.add_to_cart').click(function(){

                    var product_id= $(this).attr("id");
                    var product_name= $('#name'+product_id).val();
                    var product_price= $('#price'+product_id).val();
                    var product_image= $('#image'+product_id).val();
                    var product_quantity= $('#quantity'+product_id).val();
                    //alert(product_price);
                        $.ajax({

                            url:"includes/add_to_cart.php",
                            method:"POST",
                            data:{
                                product_id:product_id,
                                product_name:product_name,
                                product_price:product_price,
                                product_image:product_image,
                                product_quantity:product_quantity,
                            },
                              success: function(value)
                                    {
                                    swal("Success!", "Product added into cart!", "success");
                                    setInterval(function(){
                                    var quantity_id= $('#quantity_id').val();
                                    $('.quantity123').load("includes/fetch_quantity.php?id=" + $('#quantity_id').val()).fadeIn("slow");


                                    },500);

                                    }

                        });

                   });

                     setInterval(function(){
                    $('.popupcart').load("includes/fetch.php").fadeIn("slow");
                    //use in header pop_up_page

                    },500);

                 $('.add_to_cart').click(function() {
                    location.reload();
                    });


                     setInterval(function(){
                    $('.cart_products').load("includes/fetch.php").fadeIn("slow");
                    //use in header pop_up_page

                    }, 1000);


        });

        </script>

"add_to_cart.php" 只是从数据库中返回一些值,该代码与此查询无关。

感谢期待

【问题讨论】:

  • script.js 文件第 274 行中的问题 debounce(function( isTouchDevice )
  • 任何控制台错误?
  • @George 你能告诉我这个错误的解决方案吗?你认为这个错误是导致问题的原因吗,因为这段代码在 Chrome 上运行良好。
  • 只需注释第 32 行并检查
  • 这样做了,不好。

标签: javascript php jquery ajax cross-browser


【解决方案1】:

我会建议使用 class 而不是 id。或者在生成动态 id 时添加一些后缀

您在同一页面上有多个 ID #name、#city 等。

【讨论】:

  • 你认为它与 safari 浏览器有什么特定关系吗,因为在 Windows 10 操作系统的 Chrome 上一切正常?
  • 我从 chrome 访问了他的页面,但出现错误。如果它不能在 chrome 中工作,我们除了在 safari 中工作外我们还能做什么
  • Windows PC 或 MAC 上的 Chrome?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-15
  • 2018-05-16
  • 1970-01-01
  • 2018-01-14
  • 1970-01-01
  • 2011-04-15
相关资源
最近更新 更多