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

 

posted @ 2021-10-09 11:09  叨叨的蜗牛  阅读(1234)  评论(0)    收藏  举报