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
  • 951
  • 3
  • 19
  • 36
Jitender
  • 7,057
  • 25
  • 92
  • 193
  • 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

1

Works for me

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

Try This,

var xhr = $.ajax({
  type: "HEAD",
  url: "path/to/file.ext",
  success: function(msg){
    alert(msg.tostring().length);
  }
});
Manu Benjamin
  • 977
  • 9
  • 22