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
>
查看全文
相关阅读:
N-Queens And N-Queens II [LeetCode] + Generate Parentheses[LeetCode] + 回溯法
详细解释VB连接access几种方法数据库
至少原则平方多项式曲线拟合和实施
.net在arraylist用法
Microsoft.AlphaImageLoader过滤评论
总理推理算法(高效率
mysql三学习sql声明学习
1第一个Android应用程序
软件架构学习总结
ORACLE在表中添加的目光凝视和读取列
原文地址:https://www.cnblogs.com/lang/p/992363.html
最新文章
未来十年营销的主流趋势:微信营销
otg线是什么,otg线和数据线的区别介绍
JAVA8 十大新特性详解
Android 手动显示和隐藏软键盘
android中listview的一些样式设置
android软键盘的用法总结
cs模式与bs模式
B2B,B2C和C2C的区别
Java多线程,哲学家就餐问题
10个精妙的Java编码最佳实践
热门文章
浅谈导航设计,开发者必备的十大实用技巧
Vim简明教程【CoolShell】
JUnit入门
Web Service学习笔记
VB.NET 数组的定义 动态使用 多维数组
IOS成长之路-Nsstring中搜索方法rangeOfString
java反射小样例
Swift
accumulate
PIN码计算锦集
Copyright © 2011-2022 走看看