Ajax response byte size

I am using jQuery getJSONP and I want to record the call duration and response size in order to have some statistics about the use of my application. This is an ajax call for the cross domain, so I need to use JSONP, but since the JSONP call is not made with the XMLHttpRequest object, the full callback from jquery ajax does not skip the response content.

So my question is how to get the response size (content length) from a JSONP call.

$.ajaxSetup(
{
    complete:function(x,e)
    {
         log(x.responseText.length, x.responseText);
    }
}

here x is an XMLHttpRequest object for invoking JSON, but for invoking JSONP undefined.

+3
source share
2 answers

"Content-Length" :

var contentsize;
$.ajax('url', function(data, textstatus, request) {
    contentsize = request.getResponseHeader("Content-Length") / 1024;
    //do stuff with your data
});
+6
$.ajax('url',function(data,textstatus,request)
{
     var totalBytes  = request.getResponseHeader('Content-length');

     //if u are looking for downloaded bytes
     var dlBytes =request.responseText.length; 
});
0

Source: https://habr.com/ru/post/1741273/


All Articles