I upload images using Drag & Drop. Ie the "submit" button is not provided.

D & D is easy, Interests only: 1) how to take a picture from input [file] 2) send using ajax without reloading the page

Thank you very much! PS preferably without jquery, I do not want to load the whole library

    1 answer 1

    I implement it this way:

    var input = document.getElementById('Your ID input file'); var file_ = input.files[0]; if (file_) { upload_file(file_); } function upload_file(file) { var xhr = new XMLHttpRequest(); var form = new FormData(); var url; xhr.upload.onprogress = function(event) {} xhr.onload = xhr.onerror = function() { if (this.status == 200) { console.log('success'); } else { console.log('error ' + this.status); } } url = '/index.php?act=upload&a=newPhoto'; form.append('photo', file); xhr.open('POST', url, true); xhr.send(form); } 

    • Oh, it is! works!)) what you need!) - Stanislav Sagan