简体   繁体   English

为什么此JavaScript冻结IE6?

[英]Why does this JavaScript freeze IE6?

When you click, "Add to Bag" on this page, it freezes IE6 every time. 当您单击此页面上的“添加到购物袋”时,每次都会冻结IE6。 How can I figure out why it is freezing? 我怎么知道为什么冻结? Does anyone have a more direct answer? 有人有更直接的答案吗?

totallytrollbeads {dot} com {slash} Safety0.html 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;
});

It's not easy to debug a thing that freezes immediately from the outside. 调试从外部立即冻结的东西并不容易。 But it's always a good idea to cleanup the whole, remove things that are not essential, check the functionality and then do the next step. 但是清理整体,删除不必要的内容,检查功能,然后执行下一步,始终是一个好主意。

For example this: 例如:

// 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
    });
});

It's not hard to see that have this part twice there. 不难看出这部分有两次。
Put a little more accuracy into your application instead of copy&paste. 在您的应用程序中增加一些准确性,而不是复制粘贴。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM