javascript - empty responseText from xmlhttprequest -


i'm upload file using ajax,why responsetext xmlhttprequest.responsetext returned empty?

my code:

req = new xmlhttprequest();  req.file = file;  req.addeventlistener('change', changeprogress);   req.onreadystatechange =  function() { if(this.readystate == 4) {   //etc..  alert(req.responsetext); } };  req.open('post','/upload',true); req.send(file); 

uploading files in xmlhttprequest object not supported security reasons

edit: is, however, possible xmlhttprequest 2

function upload(bloborfile) {   var xhr = new xmlhttprequest();   xhr.open('post', '/server', true);   xhr.onload = function(e) { ... };    // listen upload progress.   var progressbar = document.queryselector('progress');   xhr.upload.onprogress = function(e) {     if (e.lengthcomputable) {       progressbar.value = (e.loaded / e.total) * 100;       progressbar.textcontent = progressbar.value; // fallback unsupported browsers.     }   };    xhr.send(bloborfile); }  upload(new blob(['hello world'], {type: 'text/plain'})); 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -