XMLhttp学习应用

Client.htm页面代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    
<title>客户端</title>
        
<script type="text/javascript">
        
var XmlHttp = new ActiveXObject("Microsoft.XMLhttp");
        
function sendAJAX()
        
{
            XmlHttp.Open(
"POST","receive.aspx",true);
            XmlHttp.send(
null);
            XmlHttp.onreadystatechange
=ServerProcess;
        }

        
function ServerProcess()
        
{
            
if (XmlHttp.readystate==4 || XmlHttp.readystate=='complete')
            
{
                document.getElementById('nameList').innerHTML 
=XmlHttp.responsetext;
            }

        }

        setInterval('sendAJAX()',
1000);
        
</script>
    
</head>
    
<body>
        
<div id="nameList"></div>
    
</body>
</html>

Receive.aspx CodeBehind代码:
protected void Page_Load(object sender, EventArgs e)
    
{
        PerformanceCounter myMemory 
= new PerformanceCounter();
        myMemory.CategoryName 
= "Memory";
        myMemory.CounterName 
= "Available KBytes";

        
string txtResult = "-->当前可用内存:" +myMemory.NextValue().ToString() + "KB";
        Response.Write(DateTime.Now.ToLongTimeString() 
+ txtResult);

    }
posted on 2008-06-09 17:59  Alex’Sky  阅读(244)  评论(0编辑  收藏  举报