sucary

博客园 首页 新随笔 联系 订阅 管理
 <html>
<head>
    
<title>未命名頁面</title>
    
<script language="javascript" type="text/jscript">
    
/* 定義一個未初始化的對象 */
    
var xmlhttp;
    
function createRequest()
    
{
        
// IE OR NOT
        if(window.ActiveXObject)
        
{
            xmlhttp 
= new ActiveXObject("Microsoft.XMLHTTP");
        }

        
else if(window.XMLHttpRequest)
        
{
            xmlhttp 
= new XMLHttpRequest();   
        }
    
    }

    
    
function GetValue()
    
{
        createRequest();
        xmlhttp.onreadystatechange 
= statechangeLoad;
        xmlhttp.open(
"GET","Default.aspx"true);
        xmlhttp.send(
null);
    }

    
    
function statechangeLoad()
    
{
        
// 如果請求已經完成
        if(xmlhttp.readystate == 4)
        
{
            
// 判斷請求是否成功返回
            if(xmlhttp.status == 200)
            
{
                
// 調用返回處理函數
                document.getElementById("txtShowValue").value = xmlhttp.responseText;
            }

        }

    }

    
    
</script>
</head>
<body>
    
<form id="form1" runat="server">
    
<div>
        
<input id="btnGetValue" type="button" value="Click me" onclick="GetValue();"/>
    
        
<input id="txtShowValue" type="text" />
    
</div>
    
</form>
</body>
</html>
然后另建一個Web Form,把除第一行的申明以外的所有內容刪除,在.cs文件的Page_Load加入
protected void Page_Load(object sender, EventArgs e)
    
{
        StringBuilder mystr 
= new StringBuilder();
        mystr.Append(
"Hello, Ajax!");
        Response.Write(mystr);
    }

posted on 2007-10-19 16:24  Su-Cary  阅读(404)  评论(0编辑  收藏  举报