0

Because the too much timeout errors in my requests I'd like to get the ajax answer's size in kilobytes. How can i do this? Thanks for the help.

The request is this:

$.ajax({
    url: domain+'index.php?fx_action=ajax&fx_mode=aaa&fx_id='+id,
    type: 'POST',
    dataType: 'json',
    timeout: 5000,
    beforeSend: function () {
        var currentTime = new Date()
        window.time2b = currentTime.getTime();
    }, 
    error: function (xhr, ajaxOptions, thrownError) {
        showErrorContainer();
        appendError("function fname(params) : "+thrownError+", "+xhr.responseText);
        return false;
    },
    success: function (data) {
Répás
  • 1,812
  • 7
  • 28
  • 54

3 Answers3

1

It'll be in the response header.

enter image description here

var request = $.ajax(
               ...
               success:function(msg){
                    var hdr =request.getAllResponseHeaders();
                    //parse the hdr and get the content - length
               });
Jishnu A P
  • 14,202
  • 8
  • 40
  • 50
0

It seems like you are trying to do something similar to this: Ajax HEAD request via Javascript/jQuery

Basically, you need to do a head request and then check content-length.

Community
  • 1
  • 1
jncraton
  • 9,022
  • 3
  • 34
  • 49
0

If you are sending very high chunk of data from server, its generally not recommended. You can optimize your code, to send the json data over ajax and form htlm on client side.

It will have lots of data transfer.

programmer
  • 318
  • 1
  • 6