javascript - Ajax file upload: what happens by default in form.onsubmit()? -


i have java servlet receives file, processes , writes resulting file through httpservletresponse's outputstream.

for upload, use simple form:

<form id="upload-form" action="myservlet" method="post" enctype="multipart/form-data">     select file convert:      <input type="file" id="file-select" name="myfile" />     <button type="submit" id="upload-button">upload</button> </form> 

after file has been processed, download dialog opens automatically.

since processing may take while (something 30 seconds plus upload time), wanted provide progress information through websocket on same page. works if this:

var uploadform = document.getelementbyid("upload-form"); var fileselect = document.getelementbyid("file-select"); var uploadbutton = document.getelementbyid("upload-button"); var httprequest = new xmlhttprequest();  uploadform.onsubmit = function(event) {     event.preventdefault();     event.stoppropagation();      var file = fileselect.files[0];     var formdata = new formdata();     formdata.append("myfile", file, file.name);      httprequest.open("post", "myservlet", true);     httprequest.send(formdata); }; 

the essential commands here seem event.preventdefault , event.stoppropagation.

the thing is: code, progress info - download window never appears. if comment out 2 commands, it's other way around. happens default when submitting form, , (how) can trigger manually, both progress info , resulting file?

note: i'm not using jquery far.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -