Get size of file requested via ajax

前端 未结 3 1379
心在旅途
心在旅途 2020-12-03 07:54

Here\'s what I\'m hoping to do:

I want to send an ajax request to a file (preferably with jQuery), and once the file has been loaded, determine the size of the reque

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-03 09:01

    var XHRObj = $.ajax({
        type:'HEAD',
        url:'/',
        success:function(data) {
            console.log( XHRObj.getResponseHeader('Content-Length') )
        }
    })
    

    You basically do a HEAD HTTP request and query the Content-Length, which returns X bytes.

提交回复
热议问题