Trying to upload a file to a servlet using following code:
var fd = new FormData();
fd.append("file", document.getElementById('fileToUpload').files[0]);
var xhr = new XMLHttpRequest();
xhr.upload.addEventListener("progress", uploadProgress, false);
xhr.upload.addEventListener("load", transferComplete, false);
xhr.addEventListener("error", onError, false);
xhr.addEventListener("abort", onUploadCanceled, false);
xhr.open("POST", urlManager.getUploadHandlerUrl());
xhr.send(fd);
The problem is only in chrome(works in Firefox perfectly), saying that Failed to load the resource and the problem is not consistent. It uploads once or twice at times starts shouting. When this is the error it doesnot even make call to the server.
Tried using jquery from the sample in this quesion. But no benefit.
I could not figure how something like this can happen. I appreciate any leads, thanks.
EDIT: When I wrapped my XHR and explicitly set asynchronous as told in another SO answer, it is working for atleast 3-4 uploads and starting to shout.(a bit better than earlier). I am doubtful whether it had a effect for real.
When the state change is happened I am logging the ready state and status. The readyState just jumps from 1 to 4 and the status is left with 0.