EXTJS7 监听AJAX异步上传文件进度

2020-06-19 16:45:17 浏览数 (1)

重写AJAX方法通过请求options传入为HTTPXMLRequest.upload.onprogress事件添加监听

代码语言:javascript复制
Ext.define('common.patch.Ext.data.request.Ajax', {
    override: 'Ext.data.request.Ajax',
    newRequest: function (options) {
        var xhr = this.callParent([options]);
        if (options.uploadprogress) {
            xhr.upload.onprogress = options.uploadprogress;
        }
        return xhr;
    }
});

样例

代码语言:javascript复制
Ext.Ajax.request({
	...
	uploadprogress: function (e) {
		v progress = e.loaded / e.total; // 获取上传进度
	}
	...
})

0 人点赞