<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
/* ajax 加载进度事件 可以用来写进度条*/
var xhr = new XMLHttpRequest();
xhr.addEventListener('progress', progressHandler);
xhr.addEventListener('loadstart', loadstartHandler);
xhr.addEventListener('loadend', loadendHandler);
xhr.open('get','./cat.jpg')
xhr.send();
function progressHandler(e) { console.log(e) }
function loadstartHandler(e) { console.log(e) }
function loadendHandler(e) { console.log(e) }
/*
e.total 加载文件的大小
e.loaded 当前加载的大小
*/
</script>
</body>
</html>
Ajax progress 进度条事件
最新推荐文章于 2022-09-02 09:15:11 发布