为什么这个JavaScript会冻结IE6?

时间:2010-11-29 16:52:15

标签: javascript internet-explorer-6

当您点击此页面上的“添加到行李”时,它每次都会冻结IE6。我怎么能弄清楚它冻结的原因?有人有更直接的答案吗?

totallytrollbeads {dot} com {slash} Safety0.html

function update() {
    $.ajax({
        dataType: 'json',
        type: 'POST',
        url: '/cgi-bin/ajax_cart_count.cgi',
        timeout: 2000,
        success: function (data) {
            // If bag is empty, it's see through.
            if (data.cart_count == 0) {
                $(".shopping_bag").css("opacity", ".2");
            }
            // If bag is not empty, it's not see through.
            else {
                $(".shopping_bag").css("opacity", "1");
            }
            $("#bag_total").html(data.grand_total);
            $("#bag_count").html(data.cart_count);
            window.setTimeout(update, 15000);
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            $("#bag_total").html('Timeout contacting server..');
            window.setTimeout(update, 60000);
        }
    })
}
$(document).ready(update);

// preparethe form when the DOM is ready 
$(document).ready(function () {
    // bind form using ajaxForm 
    $('.add_to_cart_form').ajaxForm({
        beforeSubmit: loading,
        success: myBox
    });
});
// preparethe form when the DOM is ready
$(document).ready(function () {
    // bind form using ajaxForm
    $('.add_to_cart_form').ajaxForm({
        beforeSubmit: loading,
        success: myBox
    });
});
// $(".add_to_cart_form").click(function () {
// $('.bypass_add_to_cart_form').ajaxForm({ success: myBox });
// });

function loading() {
    $("#loadingContent").show();
}
function myBox(resptext, statustext) {
    $("#loadingContent").hide();
    Boxy.ask(resptext, ["View Bag", "Continue Shopping"], function (val) {
        if (val == "View Bag") {
            document.location.href = "/cgi-bin/store.cgi?action=view_cart";
        }
        if (val == "Continue Shopping" && product_detail == 1) {
            history.go(-1);
        }
    }, {
        title: "Add to Bag"
    });
    $('.bypass_add_to_cart_form').ajaxForm({
        beforeSubmit: loading,
        success: myBox
    });
    update();
    return false;
}
/*     
 This tells the ajax-style add to cart that      
 it's on a product detail page so if the      
 user clicks "Continue Shopping" it takes      
 them back on step in their history.     
 */
$('.search_view').click(function () {
    product_detail = 0;
});
$('.product_view').click(function () {
    product_detail = 1;
});

1 个答案:

答案 0 :(得分:1)

调试从外部立即冻结的东西并不容易。但是清理整体,删除不重要的东西,检查功能然后再进行下一步总是一个好主意。

例如:

// preparethe form when the DOM is ready 
$(document).ready(function () {
    // bind form using ajaxForm 
    $('.add_to_cart_form').ajaxForm({
        beforeSubmit: loading,
        success: myBox
    });
});
// preparethe form when the DOM is ready
$(document).ready(function () {
    // bind form using ajaxForm
    $('.add_to_cart_form').ajaxForm({
        beforeSubmit: loading,
        success: myBox
    });
});

不难看出在那里有两次这个部分 为您的应用程序添加更多精确度,而不是复制和粘贴。