ajax在asp.net总的简单应用问题
以前在asp中用过一点ajax.很简单那种如:
res.asp文件
<%
dim mesid
mesid=request.querystring( "mid ")
response.write mesid&time()
%>
req.htm文件
<script language= "javascript ">
var receiveReq=createAjaxObj();
var mTimer;
var i=1;
function createAjaxObj()
{
var httprequest=false;
if(window.XMLHttpRequest)
{
httprequest=new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
try{
httprequest=new ActiveXObject( "Msxml2.XMLHTTP ");
}
catch(e){
try{
httprequest=new ActiveXObject( "Microsoft.XMLHTTP ");
}
catch(e){}
}
}
return httprequest
}
function getChatText(){
if(receiveReq.readyState==4||receiveReq.readyState==0){
var submitURL= "res.asp?mid= "+i;
receiveReq.open( "get ",submitURL,true);
receiveReq.onreadystatechange=handleReceiveChat;
receiveReq.send(null);
i++;
}
}
function handleReceiveChat(){
if(receiveReq.readyState==4){
var receivemes=receiveReq.responseText;
var showdiv=document.getElementById( "showmes ");
showdiv.innerHTML=receivemes;
mTimer=setTimeout( 'getChatText() ',2000);
}
}
</script>
</head>
<body onload= "getChatText() ">
<div id= "showmes "> no mes receive </div>
可以每阁2秒访问一次res.asp,所以显示时间是可以变化的,也就是动态的.
现在想在asp.net中也实现类似的功能.
可是却不行.
req.htm文件一样的
res.aspx文件为:
<script language= "c# " runat= "server ">
public void Page_Load(object sender,EventArgs e)
{
Application.Lock();
Application[ "num "]=(int)(Application[ "num "])+1;
Application.UnLock();
Page.Response.Write(Application[ "num "].ToString());
}
</script>
//Application[ "num "]已经初始化了.
req.htm显示的内容不是动态的
只有在单独刷新res.aspx文件后,req.htm中显示的内容才改变一下
不知道怎样实现.
还有就是csdn的短消息,好象是及时通知的.不知道怎样实现.有没有简单示例代码.
[解决办法]
代码太乱,建议用AjaxPro.net框架,很清晰方便。
[解决办法]
asp.net应该是一样的
------解决方案--------------------
用ajax.net