栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

XMLHttpRequest级别2-确定上传是否完成

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

XMLHttpRequest级别2-确定上传是否完成

您要监听的事件

readystatechange
在XHR对象上(不在XHR.upload上)。
readyState
4
当上载完成发送 ,并
在服务器关闭连接
loadend
/
load
在上载完成时触发,无论服务器是否关闭连接。仅供参考,以下是您可以收听以及触发的事件:

    var xhr = new XMLHttpRequest();    // ...    // do stuff with xhr    // ...    xhr.upload.addEventListener('loadstart', function(e) {      // When the request starts.    });    xhr.upload.addEventListener('progress', function(e) {      // While sending and loading data.    });    xhr.upload.addEventListener('load', function(e) {      // When the request has *successfully* completed.      // Even if the server hasn't responded that it finished.    });    xhr.upload.addEventListener('loadend', function(e) {      // When the request has completed (either in success or failure).      // Just like 'load', even if the server hasn't       // responded that it finished processing the request.    });    xhr.upload.addEventListener('error', function(e) {      // When the request has failed.    });    xhr.upload.addEventListener('abort', function(e) {      // When the request has been aborted.       // For instance, by invoking the abort() method.    });    xhr.upload.addEventListener('timeout', function(e) {      // When the author specified timeout has passed       // before the request could complete.    });    // notice that the event handler is on xhr and not xhr.upload    xhr.addEventListener('readystatechange', function(e) {      if( this.readyState === 4 ) {        // the transfer has completed and the server closed the connection.      }    });


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/410004.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号