php - Javascript image upload (Non framework) -


i'd upload image(s) via javascript (non framework). have basic example of how this?

i error message:

warning: missing boundary in multipart/form-data post data in unknown on line 0 array ( )

here i'm working far.

<form action="" method="" enctype="" id="uploadimage"> <input type="file" name="image1" id="image1" value="" > <input type="button" id="submit_button" data-data_enctype="multipart/form-data"     data-form_name="uploadimage" data-url="/gallery/images/upload/" data-change_div="getform"  value="upload" onclick="image(this.id, form.id)"/> </form>  var xmlhttp; if (window.xmlhttprequest) {     xmlhttp = new xmlhttprequest(); } else {     xmlhttp = new activexobject("microsoft.xmlhttp"); }  var datvar = document.getelementbyid(id); var url = datvar.dataset.url; var change_div = datvar.dataset.change_div;  xmlhttp.onreadystatechange = function() {     if (xmlhttp.readystate == 4 && xmlhttp.status == 200)     {         document.getelementbyid(change_div).innerhtml = xmlhttp.responsetext;     } }  xmlhttp.open("post", url, true); xmlhttp.setrequestheader("content-type", "multipart/form-data"); xmlhttp.send('null'); 

you need pass data want send xmlhttp.send() method. passing 'null' complains data missing.

something var data = document.getelementbyid('#uploadimage'); gets form. create formdata object (formdata supported in modern browsers) var formdata = new formdata(data); , passing formdata send method should do.


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -