积极答复者
js怎么释放session

问题
答案
全部回复
-
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title></title> <script language="javascript"> var xmlHttp; function showCustomer() { xmlHttp = GetXmlHttpObject(); if (xmlHttp == null) { alert("您的浏览器不支持AJAX!"); return; } var url = "ajaxd.ashx"; xmlHttp.onreadystatechange = stateChanged; xmlHttp.open("GET", url, true); xmlHttp.send(null); } function stateChanged() { if (xmlHttp.readyState == 4) { document.getElementById("sessiontext").innerHTML = xmlHttp.responseText; } } function GetXmlHttpObject() { var xmlHttp = null; try { // Firefox, Opera 8.0+, Safari xmlHttp = new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } </script> </head> <body> <form id="form1" runat="server"> <div> <span id="sessiontext"> </span> <input id="Button1" onclick="showCustomer()" type="button" value="清除session" /> </div> </form> </body> </html>
后台cs
protected void Page_Load(object sender, EventArgs e) { if ( this.Page.IsPostBack) { Session["s"] = "11"; } Response.Write(Session["s"]); }
我用的js异步的页面是ASHX 中文叫一般处理程序 你可以用aspx替代
我这个页面取名叫ajaxd.ashx只有后台代码using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; namespace WebApplication1 { /// <summary> /// $codebehindclassname$ 的摘要说明 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class ajaxd : IHttpHandler,System.Web.SessionState.IRequiresSessionState { public void ProcessRequest(HttpContext context) { HttpContext.Current.Session.RemoveAll(); context.Response.ContentType = "text/plain"; context.Response.Write("成功清除"); context.Response.End(); } public bool IsReusable { get { return false; } } } }
你操作一下浏览页面 点击 清除按钮 ‘ 然后浏览器点击刷新 可以看到session所有清除
- 已建议为答案 mldark 2009年10月17日 11:50