Blog Stats
Posts - 0
Articles - 6
Comments - 1
Trackbacks - 0
文章档案
2008年4月 (3)
2007年12月 (3)
相册
Ajax
asp.net 2.o
静
使用innerHTML属性创建动态内容
完整代码:
<!
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
>
Using responseText with innerHTML
</
title
>
<
script
language
="JavaScript"
type
="text/javascript"
>
//
创建 XmlHttpRequest 对象
function
createXmlHttpRequestObject()
{
if
(window.XMLHttpRequest)
{
return
new
XMLHttpRequest();
//
Not IE
}
else
if
(window.ActiveXObject)
{
return
new
ActiveXObject(
"
Microsoft.XMLHTTP
"
);
//
IE
}
else
{
alert(
"
Your browser doesn't support the XmlHttpRequest object. Better upgrade to Firefox.
"
);
}
}
var
receiveReq
=
createXmlHttpRequestObject();
function
GetinnerHTML()
{
if
(receiveReq.readyState
==
4
||
receiveReq.readyState
==
0
)
{
//
建立对服务器的调用,call to SayHello.html(555)
receiveReq.open(
"
GET
"
, 'innerHTML.xml',
true
);
//
每个改变时都会触发这个事件处理器,通常会调用一0个javascript函数!(666) Set the function that will be called when the XmlHttpRequest objects state changes.
receiveReq.onreadystatechange
=
CallBack;
//
向服务器发送请求
receiveReq.send(
null
);
}
}
//
CallBack()
function
CallBack()
{
if
(receiveReq.readyState
==
4
)
{
document.getElementById('span_result').innerHTML
=
receiveReq.responseText;
}
}
</
script
>
</
head
>
<
body
>
<
a
href
="javascript:GetinnerHTML();"
>
GetInnerHTML
</
a
><
br
/>
<!--
<span id="span_result"></span>
-->
<
div
id
="span_result"
></
div
>
</
body
>
</
html
>
属性
responseText
将响应提供为一个串,所以innerHTML.xml可以是一个“HelloWorld”字符串,也可以是一个表格:
<
table
border
="1"
>
<
tbody
>
<
tr
>
<
th
>
Activity Name
</
th
>
<
th
>
Location
</
th
>
<
th
>
Time
</
th
>
</
tr
>
<
tr
>
<
td
>
Waterskiing
</
td
>
<
td
>
Dock #1
</
td
>
<
td
>
9:00 AM
</
td
>
</
tr
>
<
tr
>
<
td
>
Volleyball
</
td
>
<
td
>
East Court
</
td
>
<
td
>
2:00 PM
</
td
>
</
tr
>
<
tr
>
<
td
>
Hiking
</
td
>
<
td
>
Trail 3
</
td
>
<
td
>
3:30 PM
</
td
>
</
tr
>
</
tbody
>
</
table
>
posted on 2008-04-12 12:17
学习者
阅读(309)
评论(0)
编辑
收藏
新用户注册
刷新评论列表
只有注册用户
登录
后才能发表评论。
网站导航:
博客园
IT新闻
Chat2DB
C++博客
博问
管理
Powered by:
.Text
and
ASP.NET
- Copyright © 学习者