let xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
console.log(4545)
} else if(xmlhttp.readyState == 3){
console.log(222)
}
}
xmlhttp.open('GET', 'http://localhost:7681/aa', true);
xmlhttp.send();
xmlhttp.readyState就是判斷進度,值為3就是已經在接收了,可以在這個狀態下做邏輯處理
應用場景,http傳輸方式為Transfer-Encoding:chunked 時常用到,表示傳遞的http bady未知長度