5

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.

user1874941
  • 3,013
  • 4
  • 20
  • 31

1 Answers1

3

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.

Community
  • 1
  • 1
Jam
  • 296
  • 2
  • 8