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();
}
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();
}
相关文章推荐
- asp.net利用Ajax和Jquery在前台向后台传参数并返回值,通过aspx.cs中的静态方法+WebMethod进行处理
- ASP.NET利用Ajax进行前后台值传递
- 关于ASP.NET 中使用Ajax进行异步调用问题,前台参数无法跳转到后台,提示500 internal server error
- asp.net 后台cs代码怎么操作前台用ajax实现下拉框进行搜索
- 了解使用 ASP.NET AJAX 进行局部页面更新——ASP.NET AJAX学习笔记“出自msdn”
- ASP.NET前台AJAX方法调用后台的方法写法
- asp.net jquery Ajax获得后台返回值
- 【转】【Asp.Net】了解使用 ASP.NET AJAX 进行局部页面更新
- Jquery+asp.net后台数据传到前台js进行解析的方法
- AjaxPro.dll,asp.net 前台js调用后台方法(无刷新)
- 利用JQuery的$.ajax()可以很方便的调用asp.net的后台方法。
- ajax传递给asp.net mvc 后台数组参数方式
- JQuery的$.ajax()调用asp.net的后台方法样例代码
- asp.net ajax使用C#后台代码(无参数)
- Asp.net C# 使用Newtonsoft.Json 进行通信
- Asp.net中JQuery、ajax调用后台方法总结
- 利用ajax.dll进行asp.net ajax开发
- ASP.NET下利用ajax.dll进行Ajax开发
- asp.net ajax 后台弹出提示
- Asp.net 更改Alert样式和后台注册Jquery的Ajax异步提交事件[包括处理前操作、处理后操作(注明:此方法只是作为参考,如有需要可自行修改)]