2

I have ajax request with get method which is return the some dynamic data. I want to check size of response and how much it loaded.

Basically I want to make a progress bar with javascript. There is plenty of plugins available on internet but I want to make my own with help.

So I just need reference how to get these thing done. there is two thing which I need is total data size (kb) and how much it loaded.

amit_183
  • 961
  • 3
  • 19
  • 36
Jitender
  • 7,593
  • 30
  • 104
  • 210
  • Possible duplicate of http://stackoverflow.com/questions/2645504/ajax-response-byte-size or http://stackoverflow.com/questions/11358138/get-the-length-of-jqquery-ajax-response – Jeremy Thille Jun 04 '15 at 09:48

2 Answers2

2

Works for me

 var xhr = $.ajax({
      type: "HEAD",
      url: "path/to/file.ext",
      success: function(msg){
        alert(xhr.getResponseHeader('Content-Length') + ' bytes');
      }
    });
BhandariS
  • 606
  • 8
  • 20
0

Try This,

var xhr = $.ajax({
  type: "HEAD",
  url: "path/to/file.ext",
  success: function(msg){
    alert(msg.tostring().length);
  }
});
Manu Benjamin
  • 987
  • 9
  • 24
  • length property shows number of chars but not number of bytes. It matters for unicode strings – slonma Oct 14 '22 at 08:13