Hi I am trying to measure download speed from server with ajax call and xmlwebrequest, I download a 1 mb file and check the total time. However it shows just response time from server and doesn't wait until all file loaded for 2 methods I showed below. What am I doing wrong? Any other ways are welcome. Thanks...
First method I am tring is
Second method is
First method I am tring is
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) {
})
Code:
var start = new Date();
(function rec() { var start = new Date().getTime();
var xmlHttp = new XMLHttpRequest();
xmlHttp.open('GET', "https://www.example.com/perftest/dummyFile1024",true);
xmlHttp.setRequestHeader("Cache-Control", "no-cache");
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4) {
var total=(new Date() - start)
alert(total)
};
}; xmlHttp.send(null);
})();
Comment