美文网首页
js文件上传进度

js文件上传进度

作者: FMaarten | 来源:发表于2018-12-12 16:21 被阅读0次
    $.ajax({
        url: “******”,
        cache: false,
        contentType:"multipart/form-data",
        dataType: "json",
        type: "POST",
        contentType: false,
        processData: false,
        data: formData,
        xhr:function(){
                myXhr = $.ajaxSettings.xhr();
                if(myXhr.upload){// check if upload property exists
                myXhr.upload.addEventListener('progress',function (e) {
                // event.total是需要传输的总字节,event.loaded是已经传输的字节。如果event.lengthComputable不为真,则event.total等于0
                        if (e.lengthComputable) {
                            var progress =  Math.round(e.loaded / e.total * 100)+ "%";//已上传的进度
                    }
                   },false);// for handling the progress of the upload
                }
                return myXhr;
            },
            success: function (result) {
            },
            error: function (e) {
            }
    })
    

    相关文章

      网友评论

          本文标题:js文件上传进度

          本文链接:https://www.haomeiwen.com/subject/aqlphqtx.html