eaglei22
eaglei22

Reputation: 2831

Only IE 11 losing focus on ajax call sometimes ASP.NET MVC4

I am using a boostrap dialog box to pull in a list with a quantity. After I submit my form, and open the dialog box to check to see if the quantity has updated, it seems to be stale data. I have a call with ajax to the controller and then back to the database to pull in updated info. But when I set a breakpoint in the controller (on server side) it never hits. IT ONLY kicks out of the issue when I set a breakpoint to the function calling ajax within developer tools and debugger. I don't see any console errors either.

I don't have an issue with Firefox, just IE11.. here is the code:

<script type="text/javascript">
    function LocationModal() {

        $("#GetLocBtn").attr("disabled", "disabled");
        var partNumber = $("#PartNum").val();
        var Condition = 'Z';
        var urlQry;
        var receiveIsChecked = document.getElementById('Receive').checked;

        var src = 'removed for security';
        $.ajax({
            type: "GET",
            url: src,
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            data: { partNumber: partNumber, CCODE: Condition },
            beforeSend: function () {
            },
            success: function (data) {                     
              $("#LocationModalContainer").html(data.LocationModal);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
            }
        });
    };

Upvotes: 1

Views: 514

Answers (1)

GertG
GertG

Reputation: 979

The problem is indeed that IE caches the results of Ajax calls. You can prevent that behavior either by adding cache: false to every call, like you've discovered, or setting it globally via ajaxSetup before you make any calls.

$.ajaxSetup({
    cache: false
});

The use of ajaxSetup is discouraged in the jQuery documentation, but might be a good solution for you if you don't use any plugins that might rely on the normal behavior and want to quickly make sure none of your own ajax calls is cached.

Personally, I have my doubts about how real the interference risk mentioned in the documentation is when it comes to the cache setting, since basically you just make IE behave like other browsers.

Upvotes: 2

Related Questions