JS ajax http請求如何使用實現長連接方式(進度條實現原理)


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未知長度

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM