关于利用ajax上传文件的心得
2016-07-18 19:08
309 查看
这近一直在做一个手机端稿件编辑功能,其中要上传文件到后台,之前在pc端已经完成了,但是是用的flash的上传组件。很早之前也听说html5可以用ajax上传文件了,于是百度了一下,找到了一个比较好用的,和大家一起分享一下。
html5uploader 一个js就搞定问题了(基于jqurey)。
http://www.igloolab.com/jquery-html5-uploader/
上面是下载地址,下载也比较麻烦,一定要用facebook分享之后才能下。
当然我也提供了下载资源给大家
http://download.csdn.net/download/jqriyv_wl/9579466
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.html5uploader.min.js"></script>
<script type="text/javascript">
$(function() {
$("#dropbox, #multiple").html5Uploader({
name: "foo",
postUrl: "bar.aspx"
});
});
</script>
<div id="dropbox"></div>
<input id="multiple" type="file" multiple>下面给出的是参数:
Settings
name: upload field identifier.
postUrl: the url to post the file data.
onClientAbort: Called when the read operation is aborted.
onClientError: Called when an error occurs.
onClientLoad: Called when the read operation is successfully completed.
onClientLoadEnd: Called when the read is completed, whether successful or not. This is called after either onload or onerror.
onClientLoadStart: Called when reading the data is about to begin.
onClientProgress: Called periodically while the data is being read.
onServerAbort: Called when the post operation is aborted.
onServerError: Called when an error occurs.
onServerLoad: Called when the post operation is successfully completed.
onServerLoadStart: Called when posting the data is about to begin.
onServerProgress: Called periodically while the data is being posted.
onServerReadyStateChange: A JavaScript function object that is called whenever the readyState attribute changes. The callback is called from the user interface thread.
onSuccess: Called when the post operation is successfully completed, the ReadyState is 4 and the HttpStatus is 200. Useful to get back informations from the server.
回调方法的参数大家可以在下载的原码中查看。
好了,行动起来吧。
html5uploader 一个js就搞定问题了(基于jqurey)。
http://www.igloolab.com/jquery-html5-uploader/
上面是下载地址,下载也比较麻烦,一定要用facebook分享之后才能下。
当然我也提供了下载资源给大家
http://download.csdn.net/download/jqriyv_wl/9579466
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.html5uploader.min.js"></script>
<script type="text/javascript">
$(function() {
$("#dropbox, #multiple").html5Uploader({
name: "foo",
postUrl: "bar.aspx"
});
});
</script>
<div id="dropbox"></div>
<input id="multiple" type="file" multiple>下面给出的是参数:
Settings
name: upload field identifier.
postUrl: the url to post the file data.
onClientAbort: Called when the read operation is aborted.
onClientError: Called when an error occurs.
onClientLoad: Called when the read operation is successfully completed.
onClientLoadEnd: Called when the read is completed, whether successful or not. This is called after either onload or onerror.
onClientLoadStart: Called when reading the data is about to begin.
onClientProgress: Called periodically while the data is being read.
onServerAbort: Called when the post operation is aborted.
onServerError: Called when an error occurs.
onServerLoad: Called when the post operation is successfully completed.
onServerLoadStart: Called when posting the data is about to begin.
onServerProgress: Called periodically while the data is being posted.
onServerReadyStateChange: A JavaScript function object that is called whenever the readyState attribute changes. The callback is called from the user interface thread.
onSuccess: Called when the post operation is successfully completed, the ReadyState is 4 and the HttpStatus is 200. Useful to get back informations from the server.
回调方法的参数大家可以在下载的原码中查看。
好了,行动起来吧。
相关文章推荐
- HDFS与RPC理解
- 1003. 我要通过!(20)
- ICTCLAS 汉语词性标注集 中科院
- JAVA第三天
- HDU 2544 最短路【SPFA】
- 在Android原生中嵌入React Native,进而React Native调用原生
- java正则表达式
- Hadoop的产生背景
- 简单总结协程Coroutine及Yield常见用法
- JSPatch
- java正则表达式
- 指针及距离
- 使用Fuel 8.0 部署OpenStack
- hdu 1728 逃离迷宫
- iOS开源加密相册Agony的实现(七)
- 获取包下所有类中的注解的值 (java工具类)
- iOS开源加密相册Agony的实现(七)
- cocos creator RPG游戏的背景和节点添加
- HTML DOM position 属性
- php基础之文件的上传过程