jquery $ajax({ xhr选项 }) 允许我们写原生代码来弥补jQuery的不足

97 阅读1分钟
             $.ajax({
 
                // 下面的函数,允许我们写原生代码来弥补jQuery的不足
                xhr: function () {
                    let xhr = new XMLHttpRequest();
                    // 补充上传进度事件
                    xhr.upload.onprogress = function (e) {
                        // attr方法,用于设置元素的属性
                        $('progress').attr('max', e.total).attr('value', e.loaded);
                    }
                    // 必须返回 xhr 对象
                    return xhr;
                }
                    });