Html
<input type= "File" id= "file"/>
Js
var File1=document.getelementbyid ("file"); File1.onchange=function () {var f = this.files[0];//format file var fr = new FileReader ();//Picture if (F.type.indexof (' image ')!=-1) {alert (' upload picture ');//monitor whether formatting is complete fr.onload = function () {//Create an Image object. var img = new Image ();//monitor whether the picture is loaded. Img.onload = function () {alert (' Picture loaded complete ');};/ /To the IMG address. IMG.SRC = fr.result;//adds img to the page. Document.body.appendChild (IMG);};/ /Add files that need to be formatted. Fr.readasdataurl (f); return;} if (F.type.indexof (' text ')!=-1) {alert (' uploaded text '), fr.onload = function () {console.log (fr.result);};/ /Add a text file that needs to be formatted Fr.readastext (F, ' UTF-8 '); return;} Console.log (f);}
Ajax Upload Preview