uploadify ajax插件

 

下载uploadify:http://www.uploadify.com/

 

需要的文件:

uploadify.css

jquery.uploadify.v2.1.0.min.js

swfobject.js

jquery-1.4.2.js

 

 

 

<tr>
				<td>学生照片:</td>
				<td>
					<span id="fileSpan"><input type="file" name="stuPicture" id="stuPicture"/></span>
					<span id="imgSpan" style="display:none"></span>
					<input type="hidden" name="student.stuPhoto" id="stuPhoto"/>
				</td>
				
			</tr>

 

 

 

$(document).ready(function(){
	$("#stuPicture").uploadify({
		'uploader'     : 'jQuery/uploadify/scripts/uploadify.swf',//设置uploadify路径
		'script'       : 'Student_doAjaxUpload.action',//请求响应的Action
		'cancelImg'    : 'jQuery/uploadify/cancel.png',//设置  取消按钮图片的路径
		'folder'       : '',//设置上传文件后保存的路径
		'fileDataName' : 'stuPicture',//上传文件的文件
		'auto'         : true,//设置是否自动上传
		'multi'        : false,//设置是否多文件上传
		'onComplete'   :function(event,queueId,fileObj,response){
			//因为传回的数据是字符串,通过eval方法将其转化成json格式
			var jsonObject=eval('('+response+')');
			var filePath=jsonObject.stuFile;//得到回调的图片的路径
			var img=$("<img/>").attr("src",filePath+"?now="+new Date()).attr("width","100").attr("height","50");
			$("#imgSpan").append(img).show();
			$("#fileSpan").hide();
			$("#stuPhoto").val(filePath);
		},
		'onError'      :function(event,queueID,fileObj,errorObj){
			alert("Ajax上传图片出错!请重新试过!");
		}
		
	});	
	
});

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值