日期:2014-05-17  浏览次数:20439 次

$.post问题,前辈们帮忙。
js:
  function showImg(vsn,obj) {
  if (vsn != "") {
  if (document.getElementById(vsn).style.display == "none") {
  document.getElementById(vsn).style.display = ""
  obj.title = "点击关闭图像显示";
  //$("#td_" + vsn).html("<img width='160' height='180' src='../Handler/GetImage.ashx?vsn=" + vsn + "'/>");
  $.post("../Handler/GetImage.ashx?vsn=" + vsn + "", function (data) {
  alert(data);
  document.getElementById("s_" + vsn).style.display = "none"
  $("<img/>").attr("src", data).appendTo("#td_" + vsn + "");
  });  
  }
  else {
  document.getElementById(vsn).style.display = "none";
  obj.title = "点击查看图像显示";
  }
  }
  }


ashx:
 public void ProcessRequest (HttpContext context) {
  string vsn = context.Request["vsn"].ToString();
  if (vsn!="")
  {
  string sql = "select vheadpic from visiterecord where vsn='"+ vsn +"'";
  context.Response.ContentType = "image/*";
  DataSet ds = FUJICA.DBUtility.DbHelperSQL.Query(sql);
  if (ds!=null&&ds.Tables[0].Rows.Count>0)
  {
  context.Response.BinaryWrite((byte[])ds.Tables[0].Rows[0]["vheadpic"]);  
  }
  }
  }

问题:
$("#td_" + vsn).html("<img width='160' height='180' src='../Handler/GetImage.ashx?vsn=" + vsn + "'/>");这个可以显示出来图像;

$.post("../Handler/GetImage.ashx?vsn=" + vsn + "", function (data) {
  alert(data);
  document.getElementById("s_" + vsn).style.display = "none"
  $("<img/>").attr("src", data).appendTo("#td_" + vsn + "");
  });  
却不能,请大家帮忙啊,谢谢!

------解决方案--------------------
Convert.ToBase64String()