您的位置:首页 > 其它

关于利用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.

回调方法的参数大家可以在下载的原码中查看。

好了,行动起来吧。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: