原生JS和jQuery版实现文件上传功能
- <!doctype html>
- <html lang="zh">
- <head>
- <meta charset="utf-8">
- <title>HTML5 Ajax Uploader</title>
- <script src="http://code.jquery.com/jquery-latest.js"></script>
- </head>
- <body>
- <p><input type="file" id="upfile" name="file"></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("otherParam", 1);
- /* 把文件添加到表单里 */
- fd.append("file", document.getElementById("upfile").files[0]);
- ajax.open("post", "/cyberspace/vrv/files", true);
- ajax.onload = function () {
- console.log(ajax.responseText);
- };
- ajax.send(fd);
- }
- /* jQuery 版 */
- $('#upJQuery').on('click', function () {
- var fd = new FormData();
- fd.append("otherParam", 1);
- fd.append("file", $("#upfile").get(0).files[0]);
- $.ajax({
- url: "/cyberspace/vrv/files",
- type: "POST",
- processData: false,
- contentType: false,
- data: fd,
- success: function (d) {
- console.log(d);
- }
- });
- });
- </script>
- </body>
- </html>
注:http://www.jb51.net/article/82611.htm
原生JS和jQuery版实现文件上传功能的更多相关文章
- 原生JS版和jQuery 版实现文件上传功能
<!doctype html> <html lang="zh"> <head> <meta charset="utf-8&quo ...
- Node.js新手教程——怎样实现文件上传功能
作者:zhanhailiang 日期:2014-11-16 本文将介绍怎样使用Node.js实现文件上传功能. 1. 初始化项目信息:npm init [root@~/wade/nodejs/node ...
- 转: 如何实现jQuery的Ajax文件上传
[PHP文件上传] 在开始之前,我觉得是有必要把通WEB上传文件的原理简单说一下的.实际上,在这里不管是PHP,JSP,还是ASP处理上传的文件,其实都是WEB早已把文件上传到服务器了,我们只是运用上 ...
- js 实现 input type="file" 文件上传示例代码
在开发中,文件上传必不可少但是它长得又丑.浏览的字样不能换,一般会让其隐藏点其他的标签(图片等)来时实现选择文件上传功能 在开发中,文件上传必不可少,<input type="file ...
- jQuery插件AjaxFileUpload文件上传实现Javascript多文件上传功能
Ajax file upload plugin是一个功能强大的文件上传jQuery插件,可自定义链接.或其它元素庖代传统的file表单上传结果,可实现Ajax动态提示文件上传 过程,同时支撑多文 ...
- Bootstrap fileinput.js,最好用的文件上传组件
本篇介绍如何使用bootstrap fileinput.js(最好用的文件上传组件)来进行图片的展示,上传,包括springMVC后端文件保存. 一.demo 二.插件引入 <link ty ...
- [置顶] js 实现 <input type="file" /> 文件上传
在开发中,文件上传必不可少,<input type="file" /> 是常用的上传标签,但是它长得又丑.浏览的字样不能换,我们一般会用让,<input type ...
- jquery组件WebUploader文件上传用法详解
这篇文章主要为大家详细介绍了jquery组件WebUploader文件上传用法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 WebUploader是由Baidu WebFE(FEX)团队开发的一 ...
- 使用JS实现可断点续传的文件上传方案
需求:项目要支持大文件上传功能,经过讨论,初步将文件上传大小控制在500M内,因此自己需要在项目中进行文件上传部分的调整和配置,自己将大小都以501M来进行限制. 第一步: 前端修改 由于项目使用的是 ...
随机推荐
- C++微专业课程辅导(内存模型和动态内存)
“除了静态内存和栈内存之外,每个程序还拥有一个内存池.这部分空间被称作自由空间(free store)或堆(heap).程序用堆来存储动态分配(dynamically allocate)的对象”——& ...
- 09: xmltodict 模块将xml格式转成json格式
1.1 : xmltodict 模块将xml格式转成json格式 <?xml version="1.0"?> <!--#版本号--> <data> ...
- Python3基础 file read 读取txt文件的前几个字符
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- (转)MyBatis & MyBatis Plus
(二期)3.mybatis与mybatis plus [课程三]mybatis ...运用.xmind0.1MB [课程三]mybatis...机制.xmind0.2MB [课程三]mybatis与j ...
- 【第三十六章】 metrics(4)- metrics-graphite
将metrics report给graphite(carbon-relay) 一.代码 1.pom.xml <!-- metrics-graphite --> <dependency ...
- grpc python quickstart
参考:grpc python quickstart 准备 1.升级pip $ python -m pip install --upgrade pip 2.安装grpc $ python -m pip ...
- 学习mybatis-3 step by step 篇四
日志 Mybatis内置的日志工厂提供日志功能,具体的日志实现有以下几种工具: SLF4J Apache Commons Logging Log4j 2 Log4j JDK logging 具体选择哪 ...
- 一些WGS健康体检网站和公司
1.wegen https://www.wegene.com/ 2.阅己基因 http://www.selfgene.com/
- Myeclipse中xml文件里自动提示消失解决办法
IED Eclipse Java EE IDE for Web Developers:DTD 类型约束文件 1. Window->Preferences->XML->XML C ...
- python网络编程之TCP通信实例
一. server.py import socket host="localhost" port= s=socket.socket(socket.AF_INET,socket.SO ...