我有一个$ .ajax(),它计算读取给定迭代次数的文件的时间。我有两件事需要注意。
1)我发现存储数组中每次迭代的计算时间有困难,我需要存储所有值。 //在下面的代码中,“elapsed”变量的值需要存储在数组
中2)所有存储的数组值必须传递给另一个其他html文件中存在的函数。
有人可以帮助我吗?
// used to inform the number of times ajax should read the given file ( I mean to calculate time )
for (i = 0; i < 3; i++) {
(function (i) {
setTimeout(function () {
doAjax();
}, (i * 500));
})(i);
}
function doAjax() {
$.ajax({
url: "SHI.mp4", //file which needs to be read
beforeSend: function (xhr) {
xhr.start = new Date().getTime();
},
success: function (res, status, xhr) {
var end = new Date().getTime();
var elapsed = end - xhr.start; // time taken to read the file
}
});
}