日期:2014-05-17 浏览次数:20351 次
public partial class lazytest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Session["name"] = "DMJ";
}
}
<p id="txtbox">还没有</p>
<script>
$.get("Handler.ashx", function (result) { $("#txtbox").html(result); });
</script>
public class Handler : IHttpHandler,IRequiresSessionState {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
if (HttpContext.Current.Session["name"] != null)
{
string myname =HttpContext.Current.Session["name"].ToString();
context.Response.Write(myname);
context.Response.End();
}
else
context.Response.Write("没有收到session");
}
<script>
//在页面加载完毕后再取ashx里的数据
$(document).ready(function()
{
$.get("Handler.ashx", function (result) { $("#txtbox").html(result); });
});
</script>
function PostMethod(){//post代码}
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>PostMethod()</script>");