javascript - XHR Upload Progress is 100% from the start -
I am trying to upload some files to a php script, to the new XMLHTTPRequestUpload feature, it works mostly well The upload starts, I get full feedback etc. - But progress does not work.
Given that event.loaded value- In Firefox I am getting a random value between 0 and file size; In Chrome (where I'm mostly working) I get the size of the total file, although the '4' made is not reachable and the developer tool window still shows the file to load?
Any thoughts?
This is my code:
var xhr = New XMLHttpRequest () xhr.upload.addEventListener ('progress', function (event) {if (event.lengthComputable) {$ ('AjaxfeedbackDiv'). InnerHTML = event.loaded + '/' + event.total;}}, false); Xhr.onreadystatechange = function (event) {if (event.target.readyState == 4) {updateFileList (); }}; Xhr.open ("Post", "_code / upload.php"); Xhr.setRequestHeader ("cache-control", "no-cache"); Xhr.setRequestHeader ("X-requested-with", "XMLHttpRequest"); Xhr.setRequestHeader ("x-file-size", file.size); Xhr.setRequestHeader ("X-file-type", file.type); Xhr.setRequestHeader ("content-type", "multipart / form-data"); XHR (file);
Many thanks
Ben
I recently had some difficulty in setting up event listeners for progress programs on XHR. I implemented it as an anonymous function, which works beautifully:
xhr. Upload.onprogress = function (evt) {if (evt.lengthComputable) {var percentComplete = parseInt ((evt. Loaded / evt.total) * 100); Console.log ("Upload:" + percent complete + "% complete")}};
I stumbled across one of the other guests on the other side, however, it is quite likely that one of them was accelerating my event listener . What you have got and my setup is that I am using xhr.sendAsBinary ().
Comments
Post a Comment