Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$.ajax async:false doesn't work in IE and Firefox, works in Chrome/Safari

I am trying to measure download speed with ajax call. Here is the my code

var start = new Date();
$.ajax ({
    url: 'https://www.example.com/perftest/dummyFile1024',
    cache: false,  
    success : function() {
        var total = (new Date() - start)
        alert(total)    
    },
    error : function(jqxhr, status, ex) {}
})

It doesn't wait until whole file loaded. When I add async: false, it waits for loading whole file and I am able to measure bandwidth at chrome and safari however internet explorer and firefox still works the same as async: true, they don't wait until whole file loaded. Do you have any idea how I can manage it works for I.E. and firefox as well? Thanks.

like image 650
user1874941 Avatar asked Oct 22 '22 19:10

user1874941


1 Answers

IE 8/9 cross domain requests require jQuery to use a different transport method which uses a XDomainRequest instead of the default XmlHttpRequest.

I believe the question has been answered already here: [question]: CORS with jQuery and XDomainRequest in IE8/9

For FireFox try setting the "dataType" of the content returned by the $.ajax request.

like image 102
Jam Avatar answered Oct 24 '22 13:10

Jam