//上传文件 function UploadFile(el) { var dataValue = $(el).attr("data-id"); var ele = dataValue.toLowerCase(); var f = document.getElementById('uploadFile_'+ele).files[0] var src = window.URL.createObjectURL(f); document.getElementById('uploadPreview_' + ele).src = src; top.$("#uploadPreview_" + ele).attr("src", src); $("#upload_msg_" + ele).text("上传中,请稍候..."); //上传应用图标 $.ajaxFileUpload({ url: "../../Manage/Flow/UploadFile", secureuri: false, fileElementId: ['uploadFile_' + ele], dataType: 'json', success: function (data) { if ((data.message).indexOf('error') >= 0) { $("#upload_msg_" + ele).text(data.message); $("#upload_msg_" + ele).css("color", "red"); } else { $("#" + dataValue).val(data.message); $("#upload_msg_" + ele).text("上传成功!"); $("#upload_msg_" + ele).css("color", "#0a9a2f"); } } }); }
注意要加载上传组件js .下载地址:https://blog-static.cnblogs.com/files/firstcsharp/ajaxfileupload.js
关于后台的上传代码就不用说了吧?网上一大把