0

Using a simple JQuery ajax request how would I calculate the response size of the xml object that is being returned from my webserver? Is there a specific JQuery byte size method or could I simply use the .length method with a basic maths calculation, for instance:

resultSize = (xmlObject.length / 1024);

Any help/suggestions would be appreciated.

DeanMWake
  • 893
  • 3
  • 19
  • 38
  • Is requirement to return byte size of resource before request?, during request ? – guest271314 Mar 18 '15 at 07:58
  • I would just like to calculate the returned data in the ajax method. I think my calculation does work, for instance the default success: function(data, status, xhr) method. If I use the data object like: (data.length / 1024) this gives me a value in KB. Im just not sure if there is a better way to do this. – DeanMWake Mar 18 '15 at 08:00
  • What is application ? – guest271314 Mar 18 '15 at 08:01
  • html web page with jquery. – DeanMWake Mar 18 '15 at 08:23
  • What is application of returning response byte size ? Is requirement to return byte size of resource only ? or, perform a task with returned byte size of resource ? – guest271314 Mar 18 '15 at 08:27
  • If you read the tags that I have added this is for performance-testing. There are no requirements. I am doing this to check the byte size of the returned xml so I can edit the program accordingly if the objects are too big. – DeanMWake Mar 18 '15 at 09:07
  • Try `$.ajax({url:url, type:"HEAD"})` , open `console` -> select `Network` , select -> "Headers" -> scroll to "Content-Length" . See http://stackoverflow.com/questions/2623963/webkit-refused-to-set-unsafe-header-content-length , http://stackoverflow.com/questions/17762778/how-to-calculate-content-length-in-javascript , http://code.google.com/p/chromium/issues/detail?id=58487 , http://stackoverflow.com/questions/4850288/how-can-i-access-the-content-length-header-from-a-cross-domain-ajax-request – guest271314 Mar 18 '15 at 17:13

0 Answers0