@{
ViewBag.Title= "Index";
Layout= "";
}
bindFileChange();
})
function bindFileChange()
{
$("#file1").change(function () {if ($("#file1").val().length > 0) {
ajaxFileUpload();
}
});
}
function showUploadImgs(data)
{if(data.imgList)
{
$("#dvUploadImgs").empty();for(var i indata.imgList)
{
$("#dvUploadImgs").append("
" + data.nameList[i] + "
");if (/.(jpg|jpeg|png|gif|bmp)$/.test(data.nameList[i].toLowerCase()))
{
$("#dvUploadImgs").append("
");
}
}
}
}
function ajaxFileUpload() {
$.ajaxFileUpload
(
{
url:'/Home/Upload', //用于文件上传的服务器端请求地址
type: 'post',
data: { Id:'123', name: 'lunis' }, //此参数很是严谨,写错一个引号都不行
secureuri: false, //通常设置为false
fileElementId: 'file1', //文件上传空间的id属性
dataType: 'json', //返回值类型 通常设置为json//async: false,
success: function (data, status) //服务器成功响应处理函数
{
showUploadImgs(data);if (typeof (data.error) != 'undefined') {if (data.error != '') {
alert(data.error);
}else{
alert(data.msg);
}
}//因为ajaxFileUpload把原来的file元素替换成新的file元素,因此以前绑定的change事件就失效了,须要从新绑定一下
bindFileChange();
},
error: function (data, status, e)//服务器响应失败处理函数
{
alert(e);
}
}
)return false;
}
function checkFile(fileName) {//本身添加的文件后缀名的验证
return /.(jpg|png|gif|bmp|pdf|doc|docx)$/.test(fileName) ? true: (function () {
alert('文件格式仅支持jpg|png|gif|bmp|pdf|doc|docx格式!');return false;
})();
}
*@@*