因为我的请求中的超时错误太多,我想得到ajax答案的大小,以千字节为单位。我怎样才能做到这一点?谢谢你的帮助。
请求是这样的:
$.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) {
答案 0 :(得分:1)
它将出现在响应标题中。
var request = $.ajax(
...
success:function(msg){
var hdr =request.getAllResponseHeaders();
//parse the hdr and get the content - length
});
答案 1 :(得分:0)
您似乎正在尝试执行与此类似的操作:Ajax HEAD request via Javascript/jQuery
基本上,您需要执行头部请求,然后检查内容长度。
答案 2 :(得分:0)
如果要从服务器发送非常高的数据块,通常不建议使用。 您可以优化代码,通过ajax发送json数据并在客户端形成htlm。
它将有大量的数据传输。