I want to know the size (in kbyte / byte) of the response to an ajax call (.get, .post, .ajax) - any ideas?
Thanks!
I want to know the size (in kbyte / byte) of the response to an ajax call (.get, .post, .ajax) - any ideas?
Thanks!
Just check data.length. Here is an example:
$.get('ajax/test.html', function(data) {
alert(data.length);
});
I figure you 's best check this size in the debugger tools of your browser. You can get the data length, as suggested by John Riche, but this is only the character length. The actual byte size of this data alone may vary, depending on the used encoding. And then you got your headers too.
Unfortunately I think you cannot read this information from Javascript itself.
If you use Chrome, press F12 to open the development tools, and choose 'Network', you get an overview of requests, including AJAX requests. For each request there's a byte size of both the response content and the entire response. In FireBug you should be able to see similar data.
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
});