0

I have a file uploader that works, in that the file and variable are getting uploaded, and the complete handler is getting triggered, when the upload is complete.. however the progress handler is not.. any ideas why not?... regards J

 function uploadFile_function(){ var formData = new FormData(); formData.append("var1", "jane"); formData.append("varFile", fileToUpload); var xhr = new XMLHttpRequest(); xhr.open("POST", "upload.php"); xhr.addEventListener("progress", function (ev) { alert('progress'); }, false); xhr.addEventListener("load", function (ev) { alert('complete'); }, false); xhr.send(formData); } 

2 Answers 2

1

You need to call the event listeners before calling xhr.open.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks steve, however althought that may be correct aswell, the problem still existed.. the answer was in the link you added... see below. (I plus 1 your answer :) If you want to edit your question to add the below in I will nark it as correct answer!.. thanks again
Excellent. Glad the link was able to help.
1

Progress events exist for both download and upload transfers. The download events are fired on the XMLHttpRequest object itself, as shown in the above sample. The upload events are fired on the XMLHttpRequest.upload object, as shown below:

function uploadFile_function(){ var formData = new FormData(); formData.append("var1", "trip"); formData.append("varFile", fileToUpload); var xhr = new XMLHttpRequest(); xhr.upload.addEventListener("progress", function (ev) { alert('progress'); }, false); xhr.upload.addEventListener("load", function (ev) { alert('complete'); }, false); xhr.open("POST", "upload.php"); xhr.send(formData); } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.