如何获得完成请求所需的时间?(复制)

时间:2022-10-19 19:00:52

This question already has an answer here:

这个问题已经有了答案:

when we send any ajax request, it takes some time to complete.

当我们发送任何ajax请求时,都需要一些时间来完成。

Is there any way to get that time in javascript?

有什么方法可以在javascript中获得时间吗?

i have attached a screen shot to elaborate more. kindly let me know if still unclear. i need the time thatis enclosed in red 如何获得完成请求所需的时间?(复制)

我附上了一个截图来详细说明。如果还不清楚,请告诉我。我需要用红色包裹的时间。

1 个解决方案

#1


3  

Take note of the time before the request and after the request. The difference will be the time taken to complete the request.

注意请求前和请求后的时间。不同之处在于完成请求所需的时间。

var start = new Date().getTime(),
    difference;

$.ajax({
    url: url,
    type: "POST",
    data: {
        name: "John",
        location: "Boston"
    }
}).done(function () {
    difference = new Date().getTime() - start;
});

#1


3  

Take note of the time before the request and after the request. The difference will be the time taken to complete the request.

注意请求前和请求后的时间。不同之处在于完成请求所需的时间。

var start = new Date().getTime(),
    difference;

$.ajax({
    url: url,
    type: "POST",
    data: {
        name: "John",
        location: "Boston"
    }
}).done(function () {
    difference = new Date().getTime() - start;
});