0

I have found some scripts that help me at this process but I got some problems.

Script is like below:

var data = new FormData();
//item is file which is needed to upload
  data.append('file',item);
  data.append('param1',variable);
  $.ajax({
  xhr: function() {
    var xhr = $.ajaxSettings.xhr();
    if(xhr.upload){
        xhr.upload.addEventListener("progress", function(e) {
          if (e.lengthComputable) {
            var percentComplete = e.loaded / e.total;
            percentComplete = parseInt(percentComplete * 100);
            console.log(percentComplete);

          }
    }, false);
}
return xhr;
 },
url:url,
  type: "POST",
  data:data,
  processData: false,
  contentType: false,
  success: function() {

  },

});

My problem is when I begin to upload it reach 100% suddenly (percentComplete became 100%) ,doesn't work and at the result user need to wait without percentages.Why it is not working properly,how can I solve it?And I have seen that when I open developer tab and network bar,then if I switch another option than No throttling, it begins to work.But normally it doesn't work

22
  • What do mean by "it turn 100% suddenly"? Is e.total reached? Commented Feb 10, 2017 at 17:42
  • @guest271314 yeah, I upload 10mb file, it return 100% then I am waiting 30second then it finish upload Commented Feb 10, 2017 at 17:46
  • @guest271314 I have looked at this stackoverflow.com/questions/28856729/… but it works same way,it begin from 100% then I wait for upload finish,same bug happened Commented Feb 10, 2017 at 18:11
  • @guest271314 I have only changed this !!e.dataTransfer.files.length && image to true so I will be able to upload video then I have tested and it just began from 100% Commented Feb 10, 2017 at 18:12
  • Cannot reproduce where progress element .value or e.loaded at progress event "began from 100%". Can you create a stacksnippets, or jsfiddle jsfiddle.net where javascript at linked Answer stackoverflow.com/a/29109577 "began from 100%"? Commented Feb 10, 2017 at 18:16

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.