Kenny
Kenny

Reputation: 215

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

I have a jQuery $.ajax POST that only fires on IE11 if the developer tools are open. It works fine on Chrome and Edge. The code that fires it is as follows:

$(".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());
    });

Another POST on another page works regardless. The following code creates it:

$(".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"
        });
    });

I am completely lost.

Upvotes: 1

Views: 57

Answers (1)

Ammar Hasan
Ammar Hasan

Reputation: 2516

you are doing a couple of things wrong, which may be creating the issue

firstly use var data = somethinghere instead of data = somethinghere

secondly, in the done method of first sample, use it like

.done(function () { window.location.reload() });

instead of

.done(location.reload());

one more thing, remember it as a rule, always use var if declaring new variables, also use semi-colons (add a semi-colon at the end of num array there). Such bizarre things happen in IE because it performs stricter validations.

Upvotes: 1

Related Questions