0

I have a code that calls execution of a remote code. Upon successful completion, I need to save the total time it took (the same time value that is shown in chrome developers console). The part of my ajax call is:

function callJSON(){
    $.ajax({
    type: 'POST',
    url: 'http://x.php',
    crossDomain: true,
        data: {matrix:input1[array]},
    dataType: 'text',
    success: function(res, textStatus, jqXHR) 
               {
        console.log(jqXHR.status);          
       },
               error: function (res1, textStatus, errorThrown) {alert('POST failed.');
     }
    });//AJAX
    }//CALLjsonone

the code works fine and everything is okay. I am able to get the status using console.log(jqXHR.status) code. But, I am looking for a command to get the time or size fields shown in chrome developer console. It should probably be like console.log(jqXHR.X.time); that X is what I need.

Espanta
  • 1,080
  • 1
  • 17
  • 27

2 Answers2

0

You could create a timer, something like this:

time = 0;
window.setInterval(function()
{
    time += 100;        
}, 100);

right before your ajax call, then after the call, in your success method;

console.log("call took: " + time);

and at last:

window.clearInterval();
Lars Anundskås
  • 1,345
  • 10
  • 24
0

If you wish to output time data to the console you should use console.time('bla'); console.timeEnd('bla'); (docs).

console.time devtools example

Konrad Dzwinel
  • 36,825
  • 12
  • 98
  • 105
  • I like this solution though it is again self timer and its value are different from the one Chrome itself produces. Lets see if anyone else comes up with what I exactly need. Tnx for your time dude. – Espanta Aug 19 '13 at 10:17