【问题标题】:jQuery AJAX request not working in Internet ExplorerjQuery AJAX 请求在 Internet Explorer 中不起作用
【发布时间】:2015-09-03 21:56:14
【问题描述】:

我正在尝试在页面加载时动态加载购物车,这在 Internet Explorer 之外的所有内容中都非常有效(在版本 8 和版本 11 中测试)。代码是:

<script type="text/javascript">
    $(document).ready(function($){
        $(".view_cart, .cart_close_button").click(function () {
            $("#cart_content").toggle();
            $(".view_cart").toggleClass('toggled');
            $(".cart_button").toggleClass('cart_pressed');
            $(".cart_header").toggleClass('show');           
            $(".cart_close_button").toggleClass('show');  
            $(".cart_total_icon").toggleClass('hide');              
            return false;                               
        });        

        $.get("/products/show_cart", function(cart){ // Get the contents of the url cart/show_cart
        $("#cart_content").html(cart); // Replace the information in the div #cart_content with the retrieved data
        });             

    });   

    $(window).load(function(){
      setTimeout(function(){ $('.page_message').fadeOut() }, 4000);
    });

</script>

购物车页面的 HTML(目前这是非常基本的)

<div class="content">
    <div class="grid grid-pad">
        <div class="col-1-1">
            <span class="page_message green_alert"><strong>Cart cleared.</strong> Your shopping cart has been emptied.</span>
        </div>
    </div>  

    <div class="cart_button">

        <a href="#" class="view_cart" title="View your cart"><i class="fa fa-shopping-cart fa-3x"></i> <span class="cart_header">Your Shopping Cart</span></a>
        <a href="#" title="Hide your cart" class="cart_close_button">X</a>

        <div id="cart_content">
            <p>CART STUFF GOES HERE</p>
        </div>  
    </div>
</div>

有人知道为什么 IE 不想在这里打球吗?如果我将 .get 代码添加到 click 函数中,它会起作用,但这会在打开购物车框时导致一小段延迟,我真的想避免这种情况。

编辑添加页面 HTML 和 IE 版本。

【问题讨论】:

  • 您使用的是哪个版本的 IE?同时发布您的 HTML 代码。
  • Internet explorer 8 和 11 我已经尝试过(所以假设在版本之间也是如此)我已经更新了原始问题。谢谢:-)
  • 无论如何,我认为您应该在每次点击查看购物车时刷新购物车。正如你在这里看到的jsfiddle.net/6GVBz/17 它适用于 Internet Explorer 10。你能检查一下你的 IE 上的小提琴吗?
  • 你也可以发布/products/show_cart的HTML响应吗?
  • @Phx - 感谢您的建议。是的,如果我将它添加到点击事件中效果很好,我已经尝试过了,但是每次打开购物车时的小延迟让我有点失望......不知道如何从 Internet Explorer 获取 HTML 响应(F12选项不是很清楚)但这是来自 firebug -

    你还没有任何项目。

    - 这只是一个基本的 HTML 页面。

标签: jquery ajax internet-explorer


【解决方案1】:

毕竟我认为是 jquery 版本问题。只需检查 IE =9 所需的 jquery 版本。您可以使用此代码:

<!--[if lt IE 9]>  
    <script src="jquery-1.9.0.js"></script>  
<![endif]-->  
<!--[if (gte IE 9) | (!IE)]><!-->  
    <script src="jquery-2.0.0.js"></script>  
<!--<![endif]-->

您可以使用不同版本的 IE 检查此 jsFiddle:http://jsfiddle.net/6GVBz/19/show/

查看此链接http://www.impressivewebs.com/loading-different-jquery-version-ie6-8/

【讨论】:

  • 抱歉 Phx,没有看到您再次回复的提醒! Thinks 搞定了,非常感谢 :-)
  • 这是一个可行的解决方案,但在 jQuery migrate plugin 就足够了,它正是为此目的而创建的。
猜你喜欢
  • 2012-07-31
  • 2011-07-15
  • 2012-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多