Jquery配合Asp.Net無重新整理刪除指定伺服器上的檔案!

來源:互聯網
上載者:User

標籤:http   java   os   io   檔案   for   ar   div   cti   

  1. 前台單擊檔案,jQuery刪除後台相應真實的檔案,包含了2個頁面,一個是顯示圖片的頁面,一個是傳遞檔案名稱,然後刪除真實圖片的頁面。具體的代碼如下:  
  2. ShowPics.htm:  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  4. <html xmlns="http://www.w3.org/1999/xhtml" >  
  5. <head>  
  6.     <title>Untitled Page</title>  
  7.     <script src="JS/jquery-1.4.4.js" type="text/javascript"></script>  
  8.     <script src="JS/json2.js" type="text/javascript"></script>  
  9.     <script type="text/javascript">  
  10.         $(function() {  
  11.             $("body img").click(function() {  
  12.                 var name = $(this).attr("alt");  
  13.                 $.ajax({  
  14.                 url: "DeletePicsForm.aspx",  
  15.                     data: "picname="+name,  
  16.                     datatype: "json",  
  17.                     type: "GET",  
  18.                     contentType: "application/json; charset=utf-8",  
  19.                     success: function(data, textStatus) {  
  20.                         alert(data.result);  
  21.                     },  
  22.                     error: function(XMLHttpRequest, textStatus, errorThrown) {  
  23.                         alert(XMLHttpRequest);  
  24.                     }  
  25.                 });  
  26.             });  
  27.         });  
  28.     </script>  
  29. </head>  
  30. <body>  
  31.  <div>  
  32.             <img src="Images/xiyangyang.jpg" alt="xiyangyang.jpg" />  
  33.     </div>  
  34. </body>  
  35. </html>  
  36. 具體的刪除的頁面的代碼如下:  
  37. DeletePicsForm.aspx.cs:  
  38.   protected void Page_Load(object sender, EventArgs e)  
  39.         {  
  40.             if (Request["picname"] != null)  
  41.             {  
  42.                 Response.Clear();  
  43.                 Response.ContentType = "application/json";  
  44.                 String result = "success";  
  45.                 try  
  46.                 {  
  47.                     File.Delete(Server.MapPath(@"\Images\")+Request["picname"].ToString());  
  48.                 }  
  49.                 catch (Exception ee)  
  50.                 {  
  51.                     result = ee.Message;  
  52.                 }  
  53.                 Response.Write("{\"result\":\"" +result+ "\"}");  
  54.                 Response.End();  
  55.             }  
  56.         } 

Jquery配合Asp.Net無重新整理刪除指定伺服器上的檔案!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.