1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Example 1</title>
<style type="text/css">
div.notes
{
border: 1px solid black;
padding: 10px;
}
</style>
<script type="text/javascript" src="exampleutils.js"></script>
<script type="text/javascript">
// <![CDATA[
/**
* Handler for server's response to notes.xml request.
* Notes are pulled from notes.xml and replace the
* contents of the DIV with id 'notesSection'.
*/
function notesResponseHandler()
{
// Make sure the request is loaded (readyState = 4)
if (req.readyState == 4)
{
// Make sure the status is "OK"
if (req.status == 200)
{
var swappableSection = document.getElementById('notesSection');
var notes = req.responseXML.getElementsByTagName('note');
var str = '';
for(i=0; i < notes.length; i++)
{
var noteNode = notes.item(i);
if(noteNode != null && noteNode.hasChildNodes())
{
str += noteNode.getAttribute('name') + ': ';
str += noteNode.firstChild.nodeValue + '<br />';
}
}
swappableSection.innerHTML = str;
}
else
{
alert("There was a problem retrieving the XML data:" + req.statusText);
}
}
}
// ]]>
</script>
</head>
<body>
Click <a href="javascript: xmlGet('notes.xml', notesResponseHandler);">here</a>
to get the contents of <code>notes.xml</code> from the server.
<br />
<div class="notes" id="notesSection"></div>
</body>
</html> |
Partager