1. Use jquery to call functions in aspx:
Copy codeThe Code is as follows:
Sajax ("***. aspx/DoSave", // a URL address pointing to the ASPX of the Function
Null, // parameter, the parameter required by the ASPX Function
ShowSaveResult); // jS script executed after successful execution
2. Function sajax
Copy codeThe Code is as follows:
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 ('internal server error ');}
}
});
};
3. Background functions:
Cs code
Copy codeThe Code is as follows:
[WebMethod (EnableSession = true)] // AJAX must call the declared function EnableSession in this way -- use Session to access the photo
Public static void DoSave ()
{
Byte [] byZhaoPian;
Try
{
ByZhaoPian = (byte []) (HttpContext. Current. Session ["image"]);
}
Catch
{
ByZhaoPian = new byte [0];
}
****************
}
4. How to assign values to Session ["image "]
After selecting the photo, click "OK" to convert the image to binary and assign the value to Session ["image"].
5. The method for uploading photos is not written here. Please refer to other articles.