Jquery ajax上傳文件到服務器


添加引用

<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 }
View Code


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM