zoukankan
html css js c++ java
Ajax control XML
<
html
>
<
head
>
<
title
>
Ajax Hello World
</
title
>
<
script
type
="text/javascript"
>
var
xmlHttp;
function
createXMLHttpRequest()
{
if
(window.ActiveXObject)
{
xmlHttp
=
new
ActiveXObject(
"
Microsoft.XMLHTTP
"
);
}
else
if
(window.XMLHttpRequest)
{
xmlHttp
=
new
XMLHttpRequest();
}
}
function
startRequest()
{
createXMLHttpRequest();
try
{
xmlHttp.onreadystatechange
=
handleStateChange;
xmlHttp.open(
"
GET
"
,
"
data.xml
"
,
true
);
xmlHttp.send(
null
);
}
catch
(exception)
{
alert(
"
您要访问的资源不存在!
"
);
}
}
function
handleStateChange()
{
if
(xmlHttp.readyState
==
4
)
{
if
(xmlHttp.status
==
200
||
xmlHttp.status
==
0
)
{
//
取得XML的DOM对象
var
xmlDOM
=
xmlHttp.responseXML;
//
取得XML文档的根
//
var res=document.getElementById("res");
//
res.innerHTML=xmlDOM.documentElement;
var
root
=
xmlDOM.documentElement;
try
{
//
取得<info>结果
var
info
=
root.childNodes;
//
显示返回结果
for
(
var
i
=
0
;i
<
info.length;i
++
)
//
遍历输出
alert(
"
responseXML's value:
"
+
info[i].text);
}
catch
(exception)
{ }
}
}
}
</
script
></
head
><
body
><
div
><
input
type
="button"
value
="return ajax responseXML's value"
onclick
="startRequest();"
/>
</
div
>
<
div
id
="res"
></
div
></
body
></
html
>
data.xml
<?
xml version="1.0" encoding="GB2312"
?>
<
root
>
fff
<
info
>
hello world!
</
info
>
<
goods
>
hello1
</
goods
>
<
goods
>
hello2
</
goods
>
</
root
>
查看全文
相关阅读:
从零开始~
SVN
了解下几个证书~~
重要的技术发展趋势
求职路上英语面试试题问答大全
C语言比java重要吗?
开源solr搜索服务器配置
全文索引 与 Like 的实现原理
nginx搭建多个站点
.Solr构建索引查询索引
原文地址:https://www.cnblogs.com/lang/p/992363.html
最新文章
[转]How I explained OOD to my wife
Trie树|字典树的简介及实现
[转]C++ 文件读取一行
C++ 面试基础题
Trie树|字典树的简介及实现
xxx
本本ubuntu无线上网解决
HDU2276_Kiki Little Kiki2_开关灯(构造矩阵)
HDU3032 Nim or not Nim
HDU3595_GG and MM
热门文章
HDU2254_奥运_矩阵_图论应用
HDU1575 && HDU1757(矩阵入门)
HDU2294_DP+矩阵加速(实在妙题)
HDU2971_Tower_求递推式累加
HDU1588_Gauss Fibonacci_fib有关题目的升级版
转_int ,long , long long, __int64类型的范围
HDU3094_A Chess Game_树形删边博弈
tomcat
servlet
什么是成功
Copyright © 2011-2022 走看看