Internet Explorer 11 处理 jQuery 取决于开发者工具是否打开

Internet Explorer 11 handling jQuery differently depending on whether the developer tools are open

我有一个 jQuery $.ajax POST 只有在开发者工具打开时才会在 IE11 上触发。它在 Chrome 和 Edge 上运行良好。触发它的代码如下:

$(".edit").click(function () {
        data = "id=" + $(this).attr("cart") + "&num=" + $("input.num").val();
        $.ajax({
            url: '@Url.Action("Edit","Cart")',
            data: data,
            type: "POST"
        }).done(location.reload());
    });

另一个页面上的另一个 POST 仍然有效。以下代码创建它:

$(".add").click(function () {
        var nums = [
            $(this).attr("item_id"),
            $(this).attr("quote_id"),
            $(this).attr("quantity_amount"),
            $(this).attr("cus_no")
        ]
        data = $.validator.format("item_id={0}&quote_id={1}&quantity_amount={2}&cus_no={3}", nums);
        $.ajax({
            url: '@Url.Action("Add","Cart")',
            data: data,
            type: "POST"
        });
    });

我完全迷路了。

你做错了几件事,这可能是造成问题的原因

首先使用var data = somethinghere代替data = somethinghere

其次,在第一个示例的done方法中,像

一样使用它
.done(function () { window.location.reload() });

而不是

.done(location.reload());

还有一件事,记住它作为一个规则,如果声明新变量总是使用 var,也使用分号(在 num 数组的末尾添加一个分号)。这种奇怪的事情发生在 IE 中,因为它执行更严格的验证。