这是一章jQuery ajaxupload插件实现无刷新上传文件,但是iframe上传和flash插件都是比较复杂的,所以就找了一个jquery的插件。下面通过实例代码给大家介绍使用jQuery ajaxupload插件实现无刷新上传文件功能。

代码如下
<script type="text/javascript">
	$(function () {
		var button = $('#upload');
		new AjaxUpload(button, {
			action: '/upload/imagesAjaxUpload',
			name: 'upload',
			onSubmit: function (file, ext) {
			if (!(ext && /^(jpg|jpeg|JPG|JPEG)$/.test(ext))) {
				alert('图片格式不正确,请选择 jpg 格式的文件!', '系统提示');
				return false;
			}
			// change button text, when user selects file
			button.text('上传中');
			// If you want to allow uploading only 1 file at time,
			// you can disable upload button
			this.disable();
			// Uploding -> Uploading. -> Uploading...
			interval = window.setInterval(function () {
			var text = button.text();
			if (text.length < 10) {
				button.text(text + '...');
			}else {
				button.text('上传中');
			}
			}, 200);
			},
			onComplete: function (file, response) {
			window.clearInterval(interval);
			// enable upload button
			this.enable();
			var json = eval('(' + response + ')');
			button.text('选择文件');
			$(".qr").css("display","inline");
			$(".qr>img").attr("src",json.file_name);
			$("input[name='wechat_qr']").val('/uploads/qr/'+json.file_name);
			//alert(json.file_name);
			//$("#ajaximg").html("<img src='/uploads/qr/"+json.file_name+"' />");
			//$("#wechat_qr").val('/uploads/qr/'+json.file_name);
			}
		});
	});
</script>


相关评论(0)
您是不是忘了说点什么?

友情提示:垃圾评论一律封号...

还没有评论,快来抢沙发吧!