<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>
protected void Page_Load(object sender, EventArgs e)
{
StringBuilder mystr = new StringBuilder();
mystr.Append("Hello, Ajax!");
Response.Write(mystr);
}

浙公网安备 33010602011771号