js清空session物件
HTML:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標題文件</title>
<script type="text/javascript">
var xmlhttp;
function createXmlhttp(){
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}
else if(window.ActiveXObject){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlhttp;
}
function ClearSession()
{
createXmlhttp();
var url="Service.asmx/ClearSession";
xmlhttp.open("POST",url,true);
xmlhttp.onreadystatechange=handleStateChange;
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
xmlhttp.send(queryString);
}
function handleStateChange()
{
if(xmlhttp.readyState==4)
{
if(xmlhttp.status==200)
{
//清空成功
}
}
}
</script>
</head>
<body>
<input name="Submit" type="button" onclick="ClearSession();" value="清空Session" />
</body>
WEB服務:
<%@ WebService Language="C#" class="Service" %>
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.SessionState;//不引入是不可以操作Session的
[WebService(Namespace = "http://tsingjun.cn/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
[WebMethod(true)]
public int ClearSession()
{
//清空Session程式碼
return 0;
}
}