用jquery存取照片的具體實現方法

來源:互聯網
上載者:User

1.用jquery 調用aspx內的函數:
複製代碼 代碼如下:
sajax("***.aspx/DoSave",  //一個URL地址 ,指向函數所在的ASPX
    null,//參數, 所指向的ASPX的函數所需要的參數
    showSaveResult);//執行成功之後執行的jS指令碼
 
2.函數 sajax
複製代碼 代碼如下:
function sajax(url, data, successcallback)
{   
  $.ajax({       
  type: "POST",       
  url: url,       
  data: data,       
  async: false,       
  contentType: "application/json;charset=utf-8",       
  dataType: "json",       
  success: successcallback,         
   statusCode: {           
      404: function () {                  alert('page not found');              },           
      500: function () {                  alert('內部伺服器錯誤 ');              }       
  }   
});
 };
 

3.後台函數:
cs代碼
複製代碼 代碼如下:
 [WebMethod(EnableSession = true)]   //AJAX調用的必須是 這種方式聲明的函數   EnableSession--》用Session存取照片
public static void DoSave()
{
    byte[] byZhaoPian;              
try              
{                  
    byZhaoPian = (byte[])(HttpContext.Current.Session["image"]);              
}              
catch              
{                  
    byZhaoPian = new byte[0];              
}
****************
}
 
4.如何給Session["image"]賦值

選擇好照片之後,點擊確定上傳的時候,把圖片轉換為二進位,賦值給Session["image"]

5.上傳照片的方法這裡就不在寫了,請查看其它文章

聯繫我們

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