日期:2014-05-17 浏览次数:20517 次
<%@ WebHandler Language="C#" Class="SavePhoto" %> using System; using System.Web; using System.IO; using System.Drawing; public class SavePhoto : IHttpHandler { public void ProcessRequest(HttpContext context) { //System.Web.UI.Page page = new System.Web.UI.Page(); context.Response.ContentType = "text/plain"; if (context.Request.Form["PHeight"] != null && context.Request.Form["PWidth"] != null && context.Request.Form["strBMP"] != null) { try { int height = int.Parse(context.Request.Form["PHeight"].ToString()); int width = int.Parse(context.Request.Form["PWidth"].ToString()); string strBmp = context.Request.Form["strBMP"].ToString(); SaveBmp(BuildBitmap(width, height, strBmp), context.Server.MapPath("../../../images/CameraPhoto")); //System.Web.HttpContext.Current.Response.Write("<script>alert('111');</script>"); context.Response.Write("RetMsg=true"); } catch (Exception) { context.Response.Write("RetMsg=false"); } } }
int height = int.Parse(context.Request.Form["PHeight"].ToString()); int width = int.Parse(context.Request.Form["PWidth"].ToString()); string strBmp = context.Request.Form["strBMP"].ToString(); SaveBmp(BuildBitmap(width, height, strBmp), context.Server.MapPath("../../../images/CameraPhoto")); //System.Web.HttpContext.Current.Response.Write("<script>alert('111');</script>"); context.Response.Write("<h2 style='color:green'>保存文件成功</h2><hr />文件已经保存到服务器路径:"+ context.Server.MapPath("../../../images/CameraPhoto"));
------解决方案--------------------
handler中返回状态,比如:1:成功,2:失败
ajax的回调函数中。。
if(返回值 == "1")
{
alert("成功");