Abs
Abs

Reputation: 57946

Wtf IE7 - AJAX calls using setTimeout

I have tested this on Firefox, Opera and Seamonkey. It works fine. When it comes to Internet Explorer 7. It works but upto a certain point. I am making an AJAX call to a PHP script every few seconds. In IE7 it makes the first AJAX call and it retrieves the data but it doesn't do it again ever. Even though i have a setTimeout function in the else block. WHY? :(

startTime = setTimeout('getStatus()', 5000); 

}//function convertNow

function getStatus() {

    $.ajax({
    type: "GET",
    url: "fileReader.php",
    data: 'textFile=' + fileNameTxt,
    success: function(respomse){
    textFileResponse = respomse.split(" ");
    $("#done").html("Downloading & Converting Video...<b style='font-size:17px;color:green;'>" + textFileResponse[0] + "</b><br /><b>" + properFileName + '</b>');
    }
    });//ajax

    if(textFileResponse[0]=='100.0%'){

    }
    else{       
    continueTime = setTimeout('getStatus();', 3000); 
        alert('call end');
    }

}

Apologies if any frustration comes through this question. I've been running around like a headless chicken for the past 3 hours.

Thank you for any help.

EDIT 2

I have added the full function. The setTimeout seems to be working correctly. It must be the AJAX call, am just checking what is being returned. Even stranger! It keeps returning the same value from the AJAX request and its not getting any newer values!! I think Answer 2 might have something.It may be due with cache but how do you over come that?

Upvotes: 0

Views: 3107

Answers (4)

andleer
andleer

Reputation: 22578

Not at all sure on this but are you missing the ;?

from:

setTimeout('getStatus()', 3000); 

to:

setTimeout('getStatus();', 3000); 

Upvotes: 1

greg
greg

Reputation: 1121

You could still use the GET request and simply add

cache: false

to the $.ajax request.

Upvotes: 1

Glenn
Glenn

Reputation: 8032

I noticed that textFileResponse is set in the function declaration of the success handler for the AJAX call yet referenced as an array immediately after making the AJAX call. Perhaps in IE 7 the success handler hasn't completed before the array reference which would throw a java script error, thus the setTimeout would never run.

Upvotes: 0

Ken Browning
Ken Browning

Reputation: 29101

Are you requesting the ajax call via HTTP GET as opposed to HTTP POST? IE tends to use cached results of ajax calls unless you use POST instead of GET.

EDIT: Since you've updated your question, I can see that you are indeed using the GET verb. Change it to POST and I bet your issue will be resolved.

Upvotes: 4

Related Questions