[英]How to calculate Fetching Time while fetching data from any Api in Ajax
I just want to show the amount of data fetched from Api. 我只想显示从Api提取的数据量。
output should be like 10% fetched 90 % remaining like that. 输出应该像10%一样,剩下90%那样。
I'm searching how should I calculate the amount the amount retreived and remaning data left to be fetched. 我正在搜索应如何计算退回的数量和剩余的剩余待取数据量。
I have googled and found a link: Monitoring_progress but if any body could suggest to me where to start I would much appreciate. 我已经在Google上搜索并找到了一个链接: Monitoring_progress,但是如果有任何机构可以向我建议从哪里开始,我将不胜感激。
As far as I know there is no way to get the exact time, but you can get an approximation. 据我所知,无法获得确切的时间,但是您可以得到一个近似值。
Most of the time is spent in the basecamp
servers, not in the request. 大部分时间都花在
basecamp
服务器上,而不是在请求中。 The link you posted offers a way for basecamp
to push progress messages. 您发布的链接为
basecamp
提供了一种发送进度消息的方式。 If they don't do so, you will get nothing. 如果他们不这样做,您将一无所获。
You can imagine the basecamp
servers as a wall. 您可以将
basecamp
服务器想象成一堵墙。 Behind the wall is the progress, but you can't see behind a wall and you are not allowed by basecamp
to climb it. 墙的后面是进度,但您看不到墙的后面,
basecamp
也不允许您攀登它。
You can approximate this time. 您可以估计这个时间。 With a method similar to what is posted here:
使用类似于此处发布的方法:
var ajaxTime= new Date().getTime();
$.ajax({
type: "POST",
url: "some.php",
}).done(function () {
var totalTime = new Date().getTime()-ajaxTime;
});
you can measure how long it will take to complete a request. 您可以衡量完成请求所需的时间。
Than you calculate the mean time
of all requests made to an url
. 比您计算对
url
的所有请求的mean time
。 That time will be good enough. 那个时间将足够好。
I recommend something like this: 我推荐这样的东西:
To display a fix amount of time as a percent you can do like this: 要将固定的时间显示为百分比,可以执行以下操作:
secondsPerPercent = timeInSeconds / 100
<-- this is how many seconds need to pass for a percent to be filled. secondsPerPercent = timeInSeconds / 100
<-这是要填充百分比所需要经过的秒数。 secondsPerPercent
. secondsPerPercent
更新一次百分比secondsPerPercent
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.