gs ajax percent loading
$.ajax({ url: url, data: para, dataType:'json', xhr: function () { var xhr = new window.XMLHttpRequest(); xhr.addEventListener("progress", function (evt) { console.log(evt) }, false); return xhr; }, success: function(d) { /////// console.log(d) } })
xhr.upload.addEventListener 上传!!
lengthComputable 总是 false。如果能计算,用 loaded/total 就是百分比
Network 右键 Copy Response Headers
稍微的不严格(json 必须双引号!都会导致 lengthComputable: false)!!!!!!
Content-Encoding:gzip 也不行!!!
header(“Content-Encoding: compress”); //可以!!!
HTTP/1.1 200 OK
Date: Mon, 15 Sep 2014 04:37:56 GMT
Server: Apache/2.2.22 (Unix) DAV/2 PHP/5.3.15 with Suhosin-Patch
X-Powered-By: PHP/5.3.15
Content-Length: 9703
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html
HTTP/1.1 200 OK
Date: Mon, 15 Sep 2014 07:09:02 GMT
Server: Apache/2.2.22 (Unix) DAV/2 PHP/5.3.15 with Suhosin-Patch
Last-Modified: Mon, 15 Sep 2014 03:10:07 GMT
ETag: “59aa3f7-414-50311f8cc01c0”
Accept-Ranges: bytes
Content-Length: 1044
Keep-Alive: timeout=15, max=99
Connection: Keep-Alive
Content-Type: application/json
<? ob_start(); ?>
{
“name”: “guoshuang test”
}
<?
$length = ob_get_length();
header(“Content-Length: “.$length);
//header(“X-Content-Length: “.$length);
ob_end_flush();
?>