weixin_33713350 2015-09-13 18:48 采纳率: 0%
浏览 24

上传时的Ajax进度栏

I've been trying to implement a progress bar with AJAX and I'm getting ZERO output from the code. I was wondering if anyone could let me know what I could be missing.

   $("#uploadSubmitBtn").click(function(){
    var formData = new FormData($("#mediaUploadForm")[0]);
    var usersFiles=$("#uploadBtn")[0].files;
    formData.append('usersUpload', usersFiles);
    $.ajax({

        //for our progress bar...
         xhr: function() {
         //var xhr = new window.XMLHttpRequest();
             var xhr = $.ajaxSettings.xhr();
             xhr.upload.addEventListener("progress", function(evt) {
                 alert("attempting progress calculation..");
               if (evt.lengthComputable) {
                  var percentComplete = Math.round( (evt.loaded * 100/ evt.total) );
                  console.log("percent completed = " + percentComplete);
               }
             },  false);
             return xhr;
         },//end xhr function

        //other stuff
        url : "upload",
        type : 'post',
        data : formData,
        async : false,
        cache: false,
        processData: false,
        contentType: false,
        success : function(resp){
            $('#msgBoxText').text(resp);
            $('#msgBox').slideDown("slow");
       },
    });
});//end of submitting media
  • 写回答

1条回答 默认 最新

  • 10.24 2015-09-27 14:26
    关注

    so it looks like setting the async value to true solved the issue. so code snippet now looks like so $.ajax({ url : "upload", type : 'post', data : formData, async : true, cache: true, processData: false, contentType: false,

    Thanks to those who at least looked :)

    评论

报告相同问题?

悬赏问题

  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3