davioooh
davioooh

Reputation: 24666

Internet Explorer Ajax call, cached response issue

I have this javascript function that I use in a waiting page to check if an exporting process in my web app is running or is finished:

function waitForExport(token) {
    $.ajax({
        type : "GET",
        url : 'export/status',
        data : {
            token : token
        },
        success : function(data) {
            if (data.status == 'running') {
                $('#waitContent').append('<span>RUNNING</span>');
                setTimeout("waitForExport('" + token + "')", 5000);
            }
            if (data.status == 'done') {
                $('#waitContent').append('<div>DONE</div>');
                location.href = "export/results";
            }
        },
        error : function(jqXHR, textStatus, errorThrown) {
            alert(jqXHR.responseText);
        }
    });
}

It works in Chrome and Firefox, but not in IE.

Using Internet Explorer 7/8 the process appears always running because, except the first time, it doesn't make any other server request (I verified using Eclipse debugger). It seems like it caches the first server response and then never hits the server anymore...

Any idea?

Upvotes: 1

Views: 437

Answers (1)

Ian
Ian

Reputation: 50905

You can use:

cache: false

in your $.ajax() options object.

What this does is append a _=[TIMESTAMP] to the end of the URL (without the [ ]). This makes the browser think it's always a completely different request because a different querystring is being used in the request.

Upvotes: 6

Related Questions