XMLHttpRequest 2.0与FileReader接口的方法
jsonpd的实现:
var jsonp = function (options) {
var url = options.url,
params = options.params || {},
callbackKey = options.callbackKey || 'callback',
callback = options.callback;
var script = document.createElement('script');
var arr = [];
for (var key in params) {
arr.push(key + '=' + params[key]);
}
params = arr.join('&');
script.src = encodeURI(url + '?' + callbackKey + "=callback&"+params );
document.body.appendChild(script)
window.callback = callback;
}
jsonp({
url:'http://127.0.0.1:3000',
callbackKey: 'callback',
callback:function (data) {
console.log(data)
},
params: {
key: 'excited',
},
})
有:
DOMString、Document、FormData、Blob、File、ArrayBuffer
看张大神的博客吧。http://www.zhangxinxu.com/wordpress/2013/10/understand-domstring-document-formdata-blob-file-arraybuffer/
其中的FileReader接口做一些准备:
1、FileReader接口的方法
FileReader接口有4个方法,其中3个用来读取文件,另一个用来中断读取。无论读取成功或失败,方法并不会返回读取结果,这一结果存储在result属性中。
| 方法名 | 参数 | 描述 |
|---|---|---|
| readAsBinaryString | file | 将文件读取为二进制编码 |
| readAsText | file,[encoding] | 将文件读取为文本 |
| readAsDataURL | file | 将文件读取为DataURL |
| abort | (none) | 终端读取操作 |
2、FileReader接口事件
FileReader接口包含了一套完整的事件模型,用于捕获读取文件时的状态。
| 事件 | 描述 |
| onabort | 中断 |
| onerror | 出错 |
| onloadstart | 开始 |
| onprogress | 正在读取 |
| onload | 成功读取 |
| onloadend | 读取完成,无论成功失败 |
var UpPreviewImg = function (options) {
this.upPreview(options)
}
UpPreviewImg.prototype = {
isIE :function () { //是否是IE
return !!window.ActiveXObject;
},
isIE6 :function () {//是否是IE6
return isIE() && !window.XMLHttpRequest;
},
isIE7 :function () {//是否是IE7
return isIE() && !isIE6() && !isIE8()
},
isIE8 :function () {
return isIE() && !!document.documentMode;
},
setCss : function (_this,cssOption) {
if(!_this||_this.nodeType === || _this.nodeType === || !_this.style){
return;
}
for(var cs in cssOption){
_this.style[cs] = cssOption[cs];
}
return _this;
},
upPreview:function (options) {
var _e = options.e,
preloadImg = null;
_e.onchange = function () {
var _v = this.value,
_body = document.body;
picReg = /(.JPEG|.jpeg|.JPG|.jpg|.GIF|.gif|.BMP|.bmp|.PNG|.png){}/;
if(!picReg.test(_v)){
alert("请选择正确的图片格式");
return false;
}
if(typeof FileReader == 'undefined') {
if (this.file) {
var _img = document.createElement("img");
_img.setAttribute("src", this.file.files[].getAsDataURL());
options.preview.appendChild(_img);
}
else if (this.isIE6()) {
var _img = document.createElement("img");
_img.setAttribute("src", _v);
options.preview.appendChild(_img);
}
else{
_v = _v.replace(/[('"%]/g,function (str) {
return escape(escape(str));
});
this.setCss(options.preview,{
"filter":"progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='scale',src=\'"+_v+"\')","display":"block"
});
}
}
else{
var reader = new FileReader(),
_file = this.files[];
reader.onload = (function (file) {
return function () {
var _img = document.createElement("img");
_img.setAttribute("src",this.result);
options.preview.appendChild(_img);
};
})(_file);
reader.onerror = function () {
alert("文件读取数据出错");
}
reader.readAsDataURL(_file);
}
}
}
}
module.exports = upPreviewImg;
*
* e 长传的图片
* preview 展示的div
* @param options
*/一个上传马上展示图片的插件
XMLHttpRequest 2.0与FileReader接口的方法的更多相关文章
- 毕业论文中使用的技术—FileReader接口
用来把文件读入内存,并且读取文件中的数据. FileReader接口提供了一个异步API,使用该API可以在浏览器主线程中异步访问文件系统,读取文件中的数据 FileReader接口的方法 方法名 参 ...
- HTML5学习之FileReader接口
http://blog.csdn.net/zk437092645/article/details/8745647 用来把文件读入内存,并且读取文件中的数据.FileReader接口提供了一个异步API ...
- Html5 js FileReader接口
用来把文件读入内存,并且读取文件中的数据.FileReader接口提供了一个异步API,使用该API可以在浏览器主线程中异步访问文件系统,读取文件中的数据.到目前文职,只有FF3.6+和Chrome6 ...
- as3.0 interface接口使用方法
[转]as3.0 interface接口使用方法 AS在2.0的时候就支持接口了 接口能够让你的程序更具扩展性和灵活性,打个例如 比方你定义了一个方法 代码: public function aMet ...
- HTML5 FileReader接口学习笔记
1.FileReader概述 FileReader 对象允许Web应用程序异步读取存储在用户计算机上的文件(或原始数据缓冲区)的内容,使用 File 或 Blob 对象指定要读取的文件或数据. 其中F ...
- java中获取接口(方法)中的参数名字(eclipse设置编译参数)(java8 javac -parameters)
interface接口参数 jdk1.7及以前使用spring功能实现的: 注意: 1.该功能只能获取类的方法的参数名,不能获取接口的方法的参数名. public static void test() ...
- Spring自定义一个拦截器类SomeInterceptor,实现HandlerInterceptor接口及其方法的实例
利用Spring的拦截器可以在处理器Controller方法执行前和后增加逻辑代码,了解拦截器中preHandle.postHandle和afterCompletion方法执行时机. 自定义一个拦截器 ...
- Java6.0中Comparable接口与Comparator接口详解
Java6.0中Comparable接口与Comparator接口详解 说到现在,读者应该对Comparable接口有了大概的了解,但是为什么又要有一个Comparator接口呢?难道Java的开发者 ...
- Java基础学习笔记十二 类、抽象类、接口作为方法参数和返回值以及常用API
不同修饰符使用细节 常用来修饰类.方法.变量的修饰符 public 权限修饰符,公共访问, 类,方法,成员变量 protected 权限修饰符,受保护访问, 方法,成员变量 默认什么也不写 也是一种权 ...
随机推荐
- 【Origin】jquery.barddialog.js
/// <reference path="jquery-2.1.1.min.js" /> /** * @license jquery.bardDialog 1.0.0 ...
- 使用git做服务器端代码的部署
传统部署方案 windows 远程桌面 FTP/SFTP 登录服务器pull github代码 Phing(PHP专业部署工具) git 自动部署流程图 服务器端准 ...
- uboot.lds (一)
lds文件与scatter文件相似都是决定一个可执行程序的各个段的存储位置,以及入口地址,这也是链接定位的作用.U-boot的lds文件说明如下: SECTIONS{ ... ...
- System Hold, Fix Manager before resetting counters
程序pending http://www.askmaclean.com/archives/2011/11 http://blog.itpub.net/35489/viewspace-717132/ 1 ...
- 夺命雷公狗---node.js---15之加密
node其实也给我们留下了密码的加密发送,不过一般都是用cmd5加密其实也是够了,但是sha1加密也要提下: /** * Created by leigood on 2016/8/31. */ var ...
- VNC & LSF
VNC (Virtual Network Computing)是虚拟网络计算机的缩写.VNC 是一款优秀的远程控制工具软件, 由著名的 AT&T 的欧洲研究实验室开发的.VNC 是在基于 UN ...
- [Ubuntu] Remove Byte Order Mark (BOM) from files recursively [Forward article]
Original article: http://www.yiiframework.com/wiki/570/remove-byte-order-mark-bom-from-files-recursi ...
- linux中查看硬件温度的命令
用到的命令是: sensors 这个命令来自一个叫 lm_sensors 的包. 执行 sensors-detect 可以以询问的方式做一些配置(可以选择检测哪些硬件的温度).
- javascript 正则表达式(二)
/* 正则表达式方法:test(),exec(),String对象方法:match(),search(),replace(),split() 1.test()方法: 用法: regexp对象实例.t ...
- linux常用命令简单介绍(netstat,awk,top,tail,head,less,more,cat,nl)
1.netstat netstat -tnl | grep 443 (查看443端口是否被占用) root用户,用netstat -pnl | grep 443 (还可显示出占用本机443端口的进程P ...