您的位置:首页 > 编程语言 > ASP

Asp.net Ajax与后台进行通信

2012-11-15 13:45 176 查看
前台部分:

if(confirm('确定退出登录吗?'))
{
var str="1"
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
return
}
var url="index.aspx"
url=url+"?&PassWord="+str+"&t="+new Date().getTime();

xmlHttp.onreadystatechange=url;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4)
{
if (xmlHttp.status == 200)
{
if(xmlHttp.responseText=="-1")
{
window.location="index.aspx";
}
}
}
}
xmlHttp.send(null)
}
}
//ajax定義部份
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;
}

后台部分:

protected void Page_Load(object sender, EventArgs e)
{

if (Request.Params["PassWord"] != null && Request.Params["PassWord"] != "")
{
linkBtnLogOffClick();
}

}

protected void linkBtnLogOffClick()
{
Session.Abandon();
loginAfter.Visible = false;
loginBefore.Visible = true;
Response.Write("-1");
Response.End();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: