取回服务器端 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>

 

 

 

 

 

相关文章:

  • 2021-08-07
  • 2022-01-21
  • 2021-05-21
  • 2021-10-29
  • 2022-01-19
  • 2022-12-23
  • 2021-08-05
猜你喜欢
  • 2021-05-21
  • 2021-07-21
  • 2021-08-09
  • 2022-12-23
  • 2022-01-02
  • 2022-12-23
  • 2021-08-15
相关资源
相似解决方案