jQuery.AjaxFileUpload.js是一款jQuery插件,用于通过ajax上传文件。
功能特点:
-
它不依赖于特定的HTML,只要给它一个“<INPUTTYPE="file">
-
它不需要你的服务器响应时指定任何特定方式
-
可以对大批量文件进行操作
例如:
function uploadHead(){
$.ajaxFileUpload({
url:"${contextPath}" + "/sys/sysuser/uploadBasicHead",//需要链接到服务器地址
secureuri:false,
fileElementId:"basicInfoHead",//文件选择框的id属性
dataType: 'json', //json
success: function (data) {
$("#imgHead").attr("src","${contextPath}" + "/sys/sysuser/readImage?imagePath="+data.imagePath);
$('#basicHeadUrl').val(data.imagePath);
},
error:function(XMLHttpRequest, textStatus, errorThrown){
alert('上传失败!' + errorThrown);
}
});
};
<input type="file" onchange="uploadHead();" id="basicInfoHead" style="display:none;"