会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
sucary
博客园
首页
新随笔
联系
订阅
管理
公告
ajax 基本例子
<
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
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
Powered by:
博客园
Copyright © 2024 Su-Cary
Powered by .NET 8.0 on Kubernetes