Skip to content Skip to sidebar Skip to footer

Working In Ff, Chrome But Not Ie? Whats Wrong?

My partner has created a script but he is offline at the moment so I am attempting to fix this myself. Here is the code we currently have: function progressStatus(Progress) {

Solution 1:

It's a bit difficult to tell without the value of the response, and without more context. What does the console say? Are there errors?

Also, why don't you get data from the server, and then parse the data and respond accordingly, which, among other advantages (like keeping client code in one place and enforcing structure), makes debugging cases like this much simpler? Much better than evaling it and just trusting that whatever comes back knows how to process itself.

Also as good practise, keep your javascript in javascript, and not strings which will be evaluated. So instead of your setInterval, have an anonymous function:

ProgressStatus = setInterval(function(){
  progressStatus( $('#Progress').val() );
}, 1000);

Solution 2:

Does not work means about nothing. IN the future please give more details on what not working means. I am going to assume that it means it is never updating the new status on the get request and keeps grabbing the old one.

Need to stop caching

$.ajax({
  url: "http://www.site.com/progress/"+Progress,
  cache: false,
  success: function (response) {
        // Evil Eval our responseeval(response);
    }
});

Solution 3:

As there's no standard for setInterval, the result of feeding a string as first parameter may differ between browsers. As MDC says:

code in the alternate syntax, is a string of code you want to be executed repeatedly.

This is the behaviour Firefox and Chrome exhibit.

On the other hand, IE probably parses the string once and executes that one repeatedly. This optimizes things a bit, but your function will be called with exactly the same parameter each time.

Moreover, to quote MDC again

(Using this syntax is not recommended for the same reasons as using eval())

A solution would be to read the status of Progress within the function that's called repeatedly:

functionprogressStatus() {

    varProgress = $('#Progress').val();

    // Get our progress status
    $.get('http://www.site.com/progress/'+Progress, { }, function (response) {
                                     //   ↑ don't!// Eval our responseeval(response);  // don't!
    });
}

This way you can simply call

setInterval(progressStatus, 1000);

But again, using a user modifiable input field within a URL (Progress) and eval to parse (?) a response without any kind of validation is very insecure. You should probably use a variable within a closure to maintian Progress (apart from showing it to the user).

Solution 4:

I guess the problem is cache issue in IE. Mostly IE will cache by default in the settings.

You should add one random number at the end, hope fully it should work.

functionprogressStatus(Progress) {

// Get our progress status
$.get('http://www.site.com/progress/'+Progress + "/rnd/" + Math.random(), { }, function (response) {

    // Eval our responseeval(response);
});

}

You need to handle if any URL rewriting issue.

Solution 5:

Is there a specific reason for the "" around Progress in your setInterval? Javascript does not care about types..

Try

ProgressStatus = setInterval(function(){ progressStatus(Progress); }, 1000);

IMO it's prettier, and more readable, but dunno if it'll solve your problem :)

Post a Comment for "Working In Ff, Chrome But Not Ie? Whats Wrong?"