Don't think you are, know you are

博客园 首页 新随笔 管理

 

取回服务器端 XML 文件中的 Name

 

<?xml version="1.0" encoding="utf-8" ?>
 <author>
 <name>HAHA</name>
</author>

页面代码如下: 

 

<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function findAuthor(file)
{
var xmlObj = null;
if(window.XMLHttpRequest)
{
xmlObj
= new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
xmlObj
= new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
return;
}
xmlObj.onreadystatechange
= function()
{
if(xmlObj.readyState == 4)
{
updateObj(
'author',xmlObj.responseXML.getElementsByTagName('name')[0].firstChild.data);
}
}
xmlObj.open (
'GET', file, true);
xmlObj.send (
'');
}
function updateObj(obj, data)
{
var textNode = document.createTextNode(data);
document.getElementById(obj).appendChild(textNode);
}
</script>

</head>
<body>
<h1>A simple AJAX program</h1>
<p id="obj">This page is powered by
<a id='link' href="data.xml" title="View the author." onclick="findAuthor('data.xml'); this.style.display='none'; return false">
See Author.
</a>
<span id="author" style="color: olive; font-weight: bolder"></span></p>

</body>

 

 

 

 

 

posted on 2010-06-27 17:57  炭炭  阅读(398)  评论(0编辑  收藏  举报