Note that there are some explanatory texts on larger screens.

plurals
  1. POChrome/WebKit XHR File Upload
    primarykey
    data
    text
    <p>I have searched relentlessly but just can't figure this one out. Why will this XHR connection work <strong>perfectly fine in Firefox</strong> but breaks in Chrome? I'm using this in conjunction with AngularJS, by the way.</p> <pre class="lang-js prettyprint-override"><code>$scope.upload = function(project, file) { var formData = new FormData(); //Not really sure why we have to use FormData(). Oh yeah, browsers suck. formData.append('', file.file); //The real file object is stored in this file container file.xhr = new XMLHttpRequest(); file.xhr.open('PUT', '/api/projects/'+project._id+'/files', true); //Progress event listener file.xhr.upload.onprogress = function(event) { if(event.lengthComputable) { file.uploadPercent = Math.round(event.loaded / event.total * 100); } }; //Upload complete listener file.xhr.upload.onload = function(event) { file.uploaded = true; }; //Every time the status changes file.xhr.onreadystatechange = function(event) { if(event.target.readyState == 4) { //The file has been added, so tag the ID onto the file object console.log(event.target.responseText); file._id = JSON.parse(event.target.responseText)._id; } else { return; } }; file.xhr.send(formData); }; </code></pre> <p>In Firefox, the file is sent just fine to my server, and the <code>responseText</code> is returned exactly like I'd expect. However, in Chrome, I get this error: <code>Error: INVALID_STATE_ERR: DOM Exception 11 Error: An attempt was made to use an object that is not, or is no longer, usable.</code>, which would be more helpful if it told me exactly what object was attempted to be used. I've read <a href="https://stackoverflow.com/a/5319647/371273">here</a> that I should try to set <code>async</code> to false and use <code>onreadystatechange</code>, but I'm not sure how that helps, since I'm already using <code>onreadystatechange</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload