:
Code: (demo33.jsp)
<%@ Page ContentType="Text/html;charset=utf-8"language="Java" %><HTML><Head> <title>demo33.jsp</title></Head><Body><label for= "text">Name</label><inputtype= "text"ID= "text"name= "Name"/><label for= "File">File</label><inputtype= "File"ID= "File"name= "File"/><Buttontype= "button"onclick= "Ajaxuploadfile ()">Are you sure</Button></Body><Scripttype= "Text/javascript"> functionAjaxuploadfile () {varFormData= NewFormData (); varXMLHTTP; if(window. XMLHttpRequest) {//code for ie7+, Firefox, Chrome, Opera, SafariXMLHTTP= NewXMLHttpRequest (); }Else {//code for IE6, IE5XMLHTTP= NewActiveXObject ("Microsoft.XMLHTTP"); } xmlhttp.open ("POST","/data",true); Xmlhttp.setrequestheader ("X-requested-with", "XMLHttpRequest"); Formdata.append ("name", document.getElementById ("text"). Value); Formdata.append ("file", document.getElementById ("file"). files[0]); Xmlhttp.send (FormData); Xmlhttp.onreadystatechange=function() { if(Xmlhttp.readystate==4) { if(Xmlhttp.status== $) {Console.log ("Upload Successful"+xmlhttp.responsetext); }Else{Console.log ("Upload failed"+xmlhttp.responsetext); } } } }</Script></HTML>
Native JavaScript implementation file asynchronous upload