jQuery Ajax File Upload執行個體源碼_jquery

來源:互聯網
上載者:User

本文執行個體為大家分享了jQuery Ajax File Upload執行個體源碼,供大家參考,具體內容如下

項目結構

Default.aspx
Upload.aspx
Scripts/…
style.css

效果圖

 

用戶端html代碼

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="UploadFile.aspx.vb" Inherits="Web.UploadFile" %>  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">   <title></title>   <link rel="Stylesheet" type="text/css" href="style.css" mce_href="style.css" media="all" />   <mce:script type="text/JavaScript" src="../Scripts/jQuery-1.4.1.min.js" mce_src="Scripts/jquery-1.4.1.min.js"></mce:script>   <mce:script type="text/javascript" src="../Scripts/ajaxupload.3.5.js" mce_src="Scripts/ajaxupload.3.5.js"></mce:script>   <mce:script type="text/javascript"><!--     $(function () {       var btnUpload = $('#upload');       var status = $('#status');       new AjaxUpload(btnUpload, {         action: 'Upload.aspx',         //Name of the file input box         name: 'uploadfile',         onSubmit: function (file, ext) {           if (!(ext && /^(jpg|png|jpeg|gif)$/.test(ext))) {             // check for valid file extension             status.text('Only JPG, PNG or GIF files are allowed');             return false;           }           status.text('Uploading...');         },         onComplete: function (file, response) {           //On completion clear the status           status.text('');           //Add uploaded file to list           if (response === "success") {             $('<li></li>').appendTo('#files').html('<img src="./uploads/' + file + '" mce_src="uploads/' + file + '" alt="" /><br />' + file).addClass('success');           } else {             $('<li></li>').appendTo('#files').text(file).addClass('error');           }         }       });     });     // --></mce:script> </head> <body>   <form id="form1" runat="server">   <div id="upload">     Upload File   </div>    <!-- Upload Button-->   <div id="Div1" >Upload File</div><span id="status" ></span>   <!--List Files-->   <ul id="files" ></ul>     </form> </body> </html> 

 服務端處理代碼Upload.aspx

 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls;  namespace JqueryAjaxUploadTest {   public partial class Upload : System.Web.UI.Page   {     protected void Page_Load(object sender, EventArgs e)     {       try       {         HttpPostedFile hpfFile = Request.Files["uploadfile"];         hpfFile.SaveAs(Server.MapPath("~/uploads/") + hpfFile.FileName);         Response.Write("success");       }       catch (Exception)       {          Response.Write("fail");       }     }   } }

以上就是本文的全部內容,希望對大家的學習有所協助,也希望大家多多支援雲棲社區。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.