View Full Version : Drag and drop upload with loading message

Nov 27th, 2014, 08:09 PM
I have a script that uploads images on drag & drop. The problem is the "loading" div does not show up until the image is uploaded to the server. I want it to show after the "drop" event, but before uploading the image, otherwise there is no way to know if the image is being uploaded or not.

var xhr = new XMLHttpRequest();

document.getElementById("loading").style.display = "inline";

xhr.open("POST", $id("upload").action, false);
xhr.setRequestHeader("X-FILENAME", file.name);

After the file is sent, I have setup a redirection to the uploaded image. Right after the image is uploaded it shows the "loading" div for a second.