html部分:

  //input type设为file
<input type="file" name="file" id="fileInputElement" />
<button id="submit">提交</button>

script部分

   var btn = document.getElementById('submit');
var fileInputElement = document.getElementById('fileInputElement'); btn.onclick = function () { var oMyForm = new FormData();
//append来添加文件,
oMyForm.append("afile", fileInputElement.files[]); var oReq = new XMLHttpRequest(); oReq.open("POST", "/test"); //用FormData生成的对象的好处是,send不需要setRequestHeader
oReq.send(oMyForm);
}

后台nodejs部分

const app = express();
const multer = require('multer');
var upload = multer({dest:'file/'})//multer的参数dest表示文件接受后存放的地址 app.post('/test',upload.single('afile'),(req,res)=>{ })
 
 

最新文章

  1. 5Hibernate入门----青软S2SH(笔记)
  2. linux命令:chmod
  3. Windows安装Node.Js
  4. Angular系列----AngularJS入门教程02:静态模板(转载)
  5. Form_Form Builder开发基于视图页面和自动代码生成包(案例)
  6. win7系统64位eclipse环境超详细暗黑1.4服务器搭建
  7. 判断app是否在后台
  8. Spring安全资料整理列表
  9. Watch gcc at ubuntu 12,See ELF file header
  10. Unity Chan Advanced
  11. 使用静态资源设置UI信息
  12. TODO、FIXME和XXX转载
  13. Spring + Spring MVC + Hibernate
  14. JAVA基础第二组(5道题)
  15. Webpack自动化工程
  16. cordova/phonegap/webapp性能优化方法
  17. WPF中如何调整TabControl的大小,使其跟随Window的大小而改变?
  18. mysql日期时间函数(常用的)
  19. 发布逸出 java this 逸出【转】
  20. LeetCode--018--四数之和(java)

热门文章

  1. python装饰器的简单理解
  2. [洛谷P2567] SCOI2010 幸运数字
  3. unigui ios微信界面错位和点击失灵问题
  4. POJ 1011 Sticks(搜索 &amp;&amp; 剪枝 &amp;&amp; 经典)
  5. codevs 3060 抓住那头奶牛 x
  6. (3.2)狄泰软件学院C++课程学习剖析三
  7. CF1019E Raining season
  8. 使用JLDAP操作LDAP,包含匿名连接、ldif导入导出、获取根节点、对数据的操作、LDAP错误码解析等
  9. JavaScript异步编程助手:Promise模式
  10. java.lang.OutOfMemoryError:GC overhead limit exceeded解决方