<!doctype html>
<html lang="zh">
<head>
<meta charset="utf-8">
<title>HTML5 Ajax Uploader</title>
<script src="jquery-2.1.1.min.js"></script>
</head> <body>
<p><input type="file" id="upfile"></p>
<p><input type="button" id="upJS" value="用原生JS上传"></p>
<p><input type="button" id="upJQuery" value="用jQuery上传"></p>
<script>
/*原生JS版*/
document.getElementById("upJS").onclick = function() {
/* FormData 是表单数据类 */
var fd = new FormData();
var ajax = new XMLHttpRequest();
fd.append("upload", 1);
/* 把文件添加到表单里 */
fd.append("upfile", document.getElementById("upfile").files[0]);
ajax.open("post", "test.php", true); ajax.onload = function () {
console.log(ajax.responseText);
}; ajax.send(fd); }
/* jQuery 版 */
$('#upJQuery').on('click', function() {
var fd = new FormData();
fd.append("upload", 1);
fd.append("upfile", $("#upfile").get(0).files[0]);
$.ajax({
url: "test.php",
type: "POST",
processData: false,
contentType: false,
data: fd,
success: function(d) {
console.log(d);
}
});
});
</script>
</body>
</html>

最新文章

  1. 【CodeVS】 p1696 奇怪的函数
  2. nodejs:grunt使用合并压缩的基本使用
  3. struts.xml什么时候加载
  4. PYTHON线程知识再研习F---队列同步Queue
  5. Oracle EBS-SQL (MRP-7):检查MRP计划运行报错原因之超大数据查询2.sql
  6. D - Digging(01背包,贪心)
  7. 插入排序的性能测试对比(C与C++实现)
  8. python函数式编程之装饰器(一)
  9. odoo中各视图写法
  10. 简单介绍Excel单元格行列指示的实现原理(俗称聚光灯功能)
  11. 重温IO
  12. [BZOJ 3709] Bohater
  13. vue---import的几种表现形式
  14. java 泛型 ? 和 T的区别
  15. python-opencv 图像二值化,自适应阈值处理
  16. 【转】全Javascript的Web开发架构:MEAN和Yeoman【译】
  17. jQuery之noConflict() 方法
  18. matlab直方图均衡
  19. [MVC4]Data Annotations Extensions:无法使用EmailAddress等验证特性的解决方法
  20. 解决kylin build cube第一步报错:java.lang.NullPointerException

热门文章

  1. [ZPG TEST 108] Antimonotonicity【贪心】
  2. 51nod 1138 连续整数的和
  3. Frequency of String CodeForces - 963D
  4. 配置Ubuntu16.04第02步:更改镜像源,更新系统
  5. Sping Boot返回Json格式自定义
  6. 工作记录:JS正则表达式 angularjs ng-if ng-show ng-switch
  7. AJPFX关于static总结
  8. Android 重定向 init.rc中服务的输出
  9. CSS——BFC
  10. GridSearchCV 与 RandomizedSearchCV 调参