My current challenge is uploading a file to a server using JavaScript in compliance with the CORS specification.
While there are numerous examples available online that successfully upload the file, I encounter an error as the final event being fired.
Upon examining the target, the XMLHttpRequest object reports a readyState of 4 which signifies that:
DONE: The data transfer has been completed or something went wrong during the transfer (e.g. infinite redirects).
source http://www.w3.org/TR/XMLHttpRequest/#dom-xmlhttprequest-readystate
Despite the file being uploaded successfully and the progress functioning as expected with the server responding with a 201 status code, the status returned is always 0.
A snippet of the code used for this operation:
var fd = new FormData(document.getElementById('viForm'));
var xhr = new XMLHttpRequest();
xhr.upload.addEventListener("progress", uploadProgress, false);
xhr.addEventListener("load", uploadComplete, false);
xhr.addEventListener("error", uploadFailed, false);
xhr.addEventListener("abort", uploadCanceled, false);
xhr.open("POST", submitAddress);
xhr.setRequestHeader('X-Auth-Token', token);
xhr.send(fd);
function uploadFailed(e) { console.log(e); }