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

XMLHttpRequest级别2-确定上传是否完成,第1张

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.      }    });


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5020407.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-15
下一篇 2022-11-15

发表评论

登录后才能评论

评论列表(0条)

保存