首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

用ajax读取Application里的数据有关问题 诚心求解

2012-01-19 
用ajax读取Application里的数据问题 诚心求解三个页面,前台为webform1,两个后台处理页面,分别为server.asp

用ajax读取Application里的数据问题 诚心求解
三个页面,前台为webform1,两个后台处理页面,分别为server.aspx和server1.aspx
由webform1分别向这两个页面提交请求,server.aspx采用,for(i=0;i <10;i++){Application[ "test "]   =   i;System.Threading.Thread.Sleep(5000);}提交数据到application,再用server1.aspx的
                                                      int   i   =   (int)Application[ "test "];
//Application.UnLock();
//Response.Clear();
Response.ContentType   =   "text/xml ";
Response.Write(i.ToString());
Response.End();
返回数据给webform1,在用DOM创建接收到的数据为一个新行,我的原意是能够在webform1上面一行一行的显示,但是结果是只能在server.aspx执行完之后server1.aspx才能返回。各位有什么解决办法?
代码如下


webform1.aspx
<%@   Page   language= "c# "   Codebehind= "WebForm1.aspx.cs "   AutoEventWireup= "false "   Inherits= "test.WebForm1 "   %>
<!DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.0   Transitional//EN "   >
<HTML>
<HEAD>
<title> WebForm1 </title>
<script   language= "javascript ">
var   XmlReq1,XmlReq2;
var   responseurl1   =   "server.aspx ",responseurl2   =   "server2.aspx ";
function   CreateXmlReq1()
{
try
{
XmlReq1   =   new   ActiveXObject( "Msxml2.XMLHTTP ");
}
catch(e)
{
try
{
XmlReq1   =   new   ActiveXObject( "Microsoft.XMLHTTP ");
}
catch(oc)
{
XmlReq1   =   null;
}
}
if(!XmlReq1   &&   typeof   XMLHttpRequest   !=   "undefined ")  
{
XmlReq1   =   new   XMLHttpRequest();
}
}
function   CreateXmlReq2()
{
try
{
XmlReq2   =   new   ActiveXObject( "Msxml2.XMLHTTP ");
}
catch(e)
{
try
{
XmlReq2   =   new   ActiveXObject( "Microsoft.XMLHTTP ");
}
catch(oc)
{
XmlReq2   =   null;
}
}
if(!XmlReq2   &&   typeof   XMLHttpRequest   !=   "undefined ")  
{
XmlReq2   =   new   XMLHttpRequest();
}
}
function   onloada()
{
//alert( "onloada ");
document.Form1.txt1.value   =   "wwww ";
CreateXmlReq1();
if(XmlReq1)
{
XmlReq1.onreadystatechange   =   Res1;
XmlReq1.open( "get ",responseurl1,true);
XmlReq1.send();
}
window.setInterval(test2,2000);
}
function   Res1()
{
if(   XmlReq1.readyState   ==   4)
{
if(   XmlReq1.status   ==   200)
{

}
}
}
function   test2()
{
CreateXmlReq2();
XmlReq2.onreadystatechange   =   Res2;
XmlReq2.open( "get ",responseurl2,true);
XmlReq2.send();

}
function   Res2()
{
if(   XmlReq2.readyState   ==   4)
{
if(   XmlReq2.status   ==   200)
{
document.Form1.txt1.value   +=     XmlReq2.responseText;


}
}
}

</script>
<meta   name= "GENERATOR "   Content= "Microsoft   Visual   Studio   .NET   7.1 ">
<meta   name= "CODE_LANGUAGE "   Content= "C# ">
<meta   name= "vs_defaultClientScript "   content= "JavaScript ">
<meta   name= "vs_targetSchema "   content= "http://schemas.microsoft.com/intellisense/ie5 ">
</HEAD>
<body   MS_POSITIONING= "GridLayout "   onload= "onloada() ">
<form   id= "Form1 "   method= "post "   runat= "server ">
<table   id= "Table1 ">
<tbody>
</tbody>
</table>
<INPUT   id= "txt1 "   style= "Z-INDEX:   101;   LEFT:   280px;   POSITION:   absolute;   TOP:   264px "   type= "text ">
</form>
</body>
</HTML>

server.aspx.cs

using   System;
using   System.Collections;
using   System.ComponentModel;
using   System.Data;
using   System.Drawing;
using   System.Web;
using   System.Web.SessionState;
using   System.Web.UI;
using   System.Web.UI.WebControls;
using   System.Web.UI.HtmlControls;

namespace   test
{
///   <summary>
///   server   的摘要说明。
///   </summary>
public   class   server   :   System.Web.UI.Page
{
private   void   Page_Load(object   sender,   System.EventArgs   e)
{
//   在此处放置用户代码以初始化页面
int   i   =   0;
for(i   =   0;   i   <   10;   i   ++)
{
//Application.Lock();
Application[ "test "]   =   i;
//Application.UnLock();
System.Threading.Thread.Sleep(500);
}
}

#region   Web   窗体设计器生成的代码
override   protected   void   OnInit(EventArgs   e)
{
//
//   CODEGEN:   该调用是   ASP.NET   Web   窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

///   <summary>
///   设计器支持所需的方法   -   不要使用代码编辑器修改
///   此方法的内容。
///   </summary>
private   void   InitializeComponent()
{        
this.Load   +=   new   System.EventHandler(this.Page_Load);
}
#endregion
}
}


server1.aspx.cs

using   System;
using   System.Collections;
using   System.ComponentModel;
using   System.Data;
using   System.Drawing;
using   System.Web;
using   System.Web.SessionState;
using   System.Web.UI;
using   System.Web.UI.WebControls;
using   System.Web.UI.HtmlControls;

namespace   test
{
///   <summary>
///   server2   的摘要说明。
///   </summary>
public   class   server2   :   System.Web.UI.Page
{
private   void   Page_Load(object   sender,   System.EventArgs   e)
{
//   在此处放置用户代码以初始化页面
//Application.Lock();
int   i   =   (int)Application[ "test "];


//Application.UnLock();
//Response.Clear();
Response.ContentType   =   "text/xml ";
Response.Write(i.ToString());
Response.End();
}

#region   Web   窗体设计器生成的代码
override   protected   void   OnInit(EventArgs   e)
{
//
//   CODEGEN:   该调用是   ASP.NET   Web   窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

///   <summary>
///   设计器支持所需的方法   -   不要使用代码编辑器修改
///   此方法的内容。
///   </summary>
private   void   InitializeComponent()
{        
this.Load   +=   new   System.EventHandler(this.Page_Load);
}
#endregion
}
}

这些代码可以执行,我想要的效果是server.aspx.cs循环时,i增加1,webform1的input里面就增加一个数字,
多谢大家

[解决办法]
UP!学习!
怎么和我用到的AJAX不一样啊``

热点排行