我在客户端执行 startrequest(x,y,1);
这方法定义如下:
function startrequest(x,y,state)
{
createxmlhttprequest();
xmlhttp.onreadystatechange = changed;
xmlhttp.open("get","http://localhost/WebSite3/Default.aspx?x="+x+"&y="+y+"state="+state,true);
xmlhttp.send(null);
}
request对象的创建:
var xmlhttp;
function createxmlhttprequest()
{
if(window.ActiveXObject)
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
}然后执行的服务器端方法:
if (IsPostBack)
{ if (Request.QueryString["x"] != null)
{
string s = Request.QueryString["x"] + Request.QueryString["y"] + Request.QueryString["state"];
if (Session["s"] == null)
Session.Add("s", s);
else
Session["s"] = s;
}
}
但实际上,异步调用并没有执行 Session.Add("s", s);或者也不能执行例如开连接,访问数据库的代码,请问这个问题怎么解决?
这方法定义如下:
function startrequest(x,y,state)
{
createxmlhttprequest();
xmlhttp.onreadystatechange = changed;
xmlhttp.open("get","http://localhost/WebSite3/Default.aspx?x="+x+"&y="+y+"state="+state,true);
xmlhttp.send(null);
}
request对象的创建:
var xmlhttp;
function createxmlhttprequest()
{
if(window.ActiveXObject)
{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
}然后执行的服务器端方法:
if (IsPostBack)
{ if (Request.QueryString["x"] != null)
{
string s = Request.QueryString["x"] + Request.QueryString["y"] + Request.QueryString["state"];
if (Session["s"] == null)
Session.Add("s", s);
else
Session["s"] = s;
}
}
但实际上,异步调用并没有执行 Session.Add("s", s);或者也不能执行例如开连接,访问数据库的代码,请问这个问题怎么解决?
解决方案 »
- 静态类静态构造函数 静态变量 执行顺序问题 谁帮忙解释下
- C#项目源代码文档制作,软件注册
- 关于识别验证码的?????急救!!!!!谢谢
- OOP 语言的源代码
- SharePoint2007中的方法GetCredentials(string AppID)中AppID从哪里取得?
- 关于DataSet生成的xml中的日期字段再绑定到dataGridView的格式问题
- @@C#读写数据库问题!!! 特别急 ,跪求各位大虾解决,在线等!!不下班也要等到
- C# socket断线重连等异常情况处理
- 最简单的热键问题半小时给分
- 请问,我的.net中怎么没有ADO.net控件呀?怎样显示OleDB的数据库选择对话框呀?
- 安装VS2005时出现的问题,急救啊!!!
- C#中有没有类似C++里面friend的访问修饰?
get方式
服务器
if (IsPostBack)
Post方式去处理,这样当然不行.
你访问Session可能和你当前也页面session不是同一个或者你的ajax调用有js上的不合理
你也可以用prototype.js里面的方法调用XMLHttprequest 这样至少保证的调用是正确的
改服务器if (!IsPostBack)
和xmlhttp的方式都可以
if (IsPostBack)
{ if (Request.QueryString["x"] != null)
{
string s = Request.QueryString["x"] + Request.QueryString["y"] + Request.QueryString["state"];
if (Session["s"] == null)
Session.Add("s", s);
else
Session["s"] = s;
}
}
至于这里面的代码没执行,可能还有其他原因,我能力有限..sorry