介绍
这篇文章主要介绍怎么使用原生javascript实现文件异步上,传文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
<>强效果图:强>
<强>代码:(demo33。jsp) 强>
& lt; % @ page contentType=皌ext/html; charset=UTF-8",语言=癹ava", %比; & lt; html> & lt; head> ,& lt; title> demo33.jsp & lt;/head> & lt; body> 为=& lt; label “text"祝辞名称& lt;/label> & lt; input 类型=皌ext", id=皌ext", name=皀ame"/比; 为=& lt; label “file"祝辞文件& lt;/label> & lt; input 类型=癴ile", id=癴ile", name=癴ile"/比; & lt; button 类型=癰utton", onclick=癮jaxUploadFile()“祝辞确定& lt;/button> & lt;/body> & lt; script 类型=拔谋?javascript"比; ,function ajaxUploadFile (), { var 才能;formData =, new FormData (); var 才能;xmlhttp; if 才能;(window.XMLHttpRequest), {//, code for IE7 +,火狐,Chrome, Opera, Safari ,,xmlhttp =, new XMLHttpRequest (); ,,}else {//, code for IE6,, IE5 ,,xmlhttp =, new ActiveXObject (“Microsoft.XMLHTTP"); ,,} xmlhttp.open才能(“POST",“/data", true); xmlhttp.setRequestHeader才能(“X-Requested-With",,“XMLHttpRequest"); formData.append才能(“name", . getelementbyid (“text") value); formData.append才能(“file", . getelementbyid (“file") .files [0]); xmlhttp.send才能(formData); xmlhttp.onreadystatechange才能=function (), { ,,if (xmlhttp.readyState==4), { ,,,if (xmlhttp.status==200), { ,,,,console.log(“上传成功“+ xmlhttp.responseText); ,,,}else { ,,,,console.log(“上传失败“+ xmlhttp.responseText); ,,,} ,,} ,,} ,} & lt;/script> & lt;/html>
以上是“怎么使用原生javascript实现文件异步上传”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!