ajax response byte size

前端 未结 2 1030
花落未央
花落未央 2020-12-10 21:29

I\'m using jQuery\'s getJSONP and I want to log the duration of the call and the size of the response to be able to have some statistics about the usage of my application.

相关标签:
2条回答
  • 2020-12-10 21:49

    you can get the "Content-Length" of the response header:

    var contentsize;
    $.ajax('url', function(data, textstatus, request) {
        contentsize = request.getResponseHeader("Content-Length") / 1024;
        //do stuff with your data
    });
    
    0 讨论(0)
  • 2020-12-10 21:51
    $.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 讨论(0)
提交回复
热议问题