开发者

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

开发者 https://www.devze.com 2023-03-14 23:35 出处:网络
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.

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 req开发者_Go百科uest 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) {


It'll be in the response header.

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

var request = $.ajax(
               ...
               success:function(msg){
                    var hdr =request.getAllResponseHeaders();
                    //parse the hdr and get the content - length
               });


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消