Drag and Drop and Automatically Send to the Server

Drag and Drop and Automatically Send to the Server

var formData =newFormData();for(var i =0; i < files.length; i++){
  formData.append('file', files[i]);}// now post a new XHR requestvar xhr =newXMLHttpRequest();
xhr.open('POST','/upload');
xhr.onload =function(){
  if(xhr.status ===200){
    console.log('all done: '+ xhr.status);
  }else{
    console.log('Something went terribly wrong...');
  }};

xhr.send(formData);



xhr.upload.onprogress = function (event) {
  if (event.lengthComputable) {
    var complete = (event.loaded / event.total * 100 | 0);
    progress.value = progress.innerHTML = complete;
  }
};

xhr.onload = function () {
  // just in case we get stuck around 99%
  progress.value = progress.innerHTML = 100;
};
 
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s