xhr upload fires with every submit

时间:2015-12-13 00:18:30

标签: javascript jquery ajax

I have an ajax submit with an xhr upload percentage.

  var xhr=new window.XMLHttpRequest()
  $.ajax({
    xhr:function(){
      xhr.upload.addEventListener("progress",function(event){
        if(event.lengthComputable){ 
          element.val(Math.round((event.loaded/event.total)*100)+"%")
        }
      },false)
      return xhr
    },
  )}

Unfortunately, it fires with every submit event. I thought it would only fire with uploads. How can I fix this issue?

0 个答案:

没有答案