1. 程式人生 > >jquery ajax fileinput封裝上傳外掛回撥方法

jquery ajax fileinput封裝上傳外掛回撥方法

//上傳檔案
function fileInputUpload(id,url,successfn){
	$("#"+id).fileinput({
		language: 'zh', //設定語言
		overwriteInitial: true,
		maxFileSize: 20480,
		allowedFileExtensions: ['doc', 'docx', 'pdf', 'zip', 'rar', 'xls', 'xlsx','jpg','jpeg','png'],
		uploadAsync: true,
		showPreview: false,
		showRemove:
true, uploadUrl: url, ajaxSettings: { async: false, dataType: 'json', success: function(result) { successfn(result); } } }); } //上傳檔案呼叫 fileInputUpload("uploadFile","${ctx}/upload.do",function(result){ var path = '',name='',html = ''; $(result).each(function(index, item) { path +=
item.relativePath + ';' name += item.fileName+';'; html += '<p><a href="' + item.relativePath + '" class="colorActive" target="_blank">' + item.fileName + '</a></p>' }); $('#extFilePath').val(path.substr(0, path.length - 1)); $('#extFileName').val(name.substr(0, name.length -
1)); $('.js_file_show').html(html); });