如何知道ajax请求中响应的大小 [英] How to know size of response in ajax request

查看:103
本文介绍了如何知道ajax请求中响应的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过get方法收到了ajax请求,该方法返回了一些动态数据.我想检查响应的大小以及加载的数量.

I have ajax request with get method which is return the some dynamic data. I want to check size of response and how much it loaded.

基本上,我想使用javascript制作进度条.互联网上有很多可用的插件,但我想借助自己的帮助.

Basically I want to make a progress bar with javascript. There is plenty of plugins available on internet but I want to make my own with help.

所以我只需要参考如何完成这些事情.我需要做的两件事是总数据大小(kb)和装入的数据量.

So I just need reference how to get these thing done. there is two thing which I need is total data size (kb) and how much it loaded.

推荐答案

为我工作

 var xhr = $.ajax({
      type: "HEAD",
      url: "path/to/file.ext",
      success: function(msg){
        alert(xhr.getResponseHeader('Content-Length') + ' bytes');
      }
    });

这篇关于如何知道ajax请求中响应的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆