关于利用ajax上传文件的心得

前端之家收集整理的这篇文章主要介绍了关于利用ajax上传文件的心得前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

这近一直在做一个手机端稿件编辑功能,其中要上传文件后台,之前在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.

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

好了,行动起来吧。

原文链接:https://www.f2er.com/ajax/162028.html

猜你在找的Ajax相关文章