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