1

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

Is there any way to get that time in 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 enter image description here

baig772
  • 3,404
  • 11
  • 48
  • 93

1 Answers1

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;
});
martynas
  • 12,120
  • 3
  • 55
  • 60
  • You don't even need `.getTime()`, since the dates will automatically be converted into milliseconds when you subtract them. – Blazemonger May 14 '14 at 21:58