添加引用
<script src="/js/ajaxfileupload.js"></script>
js文件 http://files.cnblogs.com/files/tengfei8/ajaxfileupload.js
上傳附件代碼:
1 //文件上傳 2 function ajaxFileUpload() { 3 $.ajaxFileUpload 4 ({ 5 url: '/ApproveListHandler.aspx?Type=UpLoadAttachment', //用於文件上傳的服務器端請求地址 6 secureuri: false, //是否需要安全協議,一般設置為false 7 fileElementId: 'txtAttachment', //文件上傳域的ID 8 dataType: 'json', //返回值類型 一般設置為json 9 success: function (data, status) //服務器成功響應處理函數 10 { 11 if (typeof (data.error) != 'undefined') { 12 if (data.error != '') { 13 $("#attTable").append("<tr class='attContent'><td class='att_title' colspan='2' >" + "附件添加失敗" + "</td></tr>"); 14 } else { 15 var displayName = data.oldFileName; 16 var fullname = data.fileName; 17 allAttFullPath = allAttFullPath + fullname + "*"; 18 $("#hdAttContent").val(allAttFullPath); 19 $("#attTable").append("<tr class='attContent'><td class='att_title'>" + displayName + "</td><td onclick='delTr(this);' class='delTd'><input type='hidden' value='" + fullname + "' /><img src='/images/selected/list_delete.png'></td></tr>"); 20 } 21 } 22 }, 23 error: function (data, status, e)//服務器響應失敗處理函數 24 { 25 $("#attTable").append("<tr class='attContent'><td class='att_title' colspan='2' >" + "附件添加失敗,服務器響應失敗,請聯系管理員" + "</td></tr>"); 26 } 27 }); 28 return false; 29 }
