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
| <html>
<head>
<script type="text/javascript" language="JavaScript1.2">
function ajax()
{
var xhr=null;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
//on définit l'appel de la fonction au retour serveur
xhr.onreadystatechange = function() { alert_ajax(xhr); };
//on appelle le fichier reponse.txt
xhr.open("GET", "xml/global.xml", true);
xhr.send(null);
}
function alert_ajax(xhr)
{
var docXML= xhr.responseXML;
var items = docXML.getElementsByTagName("donnee")
//on fait juste une boucle sur chaque élément "donnee" trouvé
for (i=0;i<items.length;i++)
{
alert (items.item(i).firstChild.data);
}
}
</script>
</head>
<body>
<a href="javascript:ajax();">Cliquez-moi toujours !</a>
</body>
</html> |
Partager