How can I access/read jqXHR fields from my program

337 Views Asked by At

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.

2

There are 2 best solutions below

2
On

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();
1
On

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

console.time devtools example