Répás
Répás

Reputation: 1820

Is there a method to get the ajax data's size in kilobyte?

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) {

Upvotes: 0

Views: 843

Answers (3)

programmer
programmer

Reputation: 318

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.

Upvotes: 0

Jishnu A P
Jishnu A P

Reputation: 14380

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
               });

Upvotes: 1

jncraton
jncraton

Reputation: 9132

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.

Upvotes: 0

Related Questions