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
|
<html>
<head>
<title>ajax</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script>
function affiche(Element,Valeur){
if (document.getElementById) document.getElementById(Element).innerHTML =Valeur;
else if (document.all) document.all[Element].innerHTML =Valeur;
}
function Test_Pseudo()
{
var xhr=null;
if (window.XMLHttpRequest) xhr = new XMLHttpRequest(); // Mozilla, Safari,...
else if (window.ActiveXObject) xhr = new ActiveXObject("Msxml2.XMLHTTP"); // Start IE
if (!xhr) { alert('Cannot create XMLHTTP instance'); return false; }
//on définit l'appel de la fonction au retour serveur
xhr.onreadystatechange = function() { alert_ajax(xhr); };
affiche("affiche","attente...");
//on affiche le message d'acceuil
//on appelle le fichier reponse.txt
xhr.open('GET', 'affiche.php', true);
xhr.send(null);
}
function alert_ajax(xhr){
if (xhr.status != 200) affiche("affiche","ERREUR DE SERVEUR");
if ((xhr.readyState==0)&&(xhr.status == 200)) affiche("affiche","pas assigné");
if ((xhr.readyState==1)&&(xhr.status == 200)) affiche("etat","en chargement...");
if ((xhr.readyState==2)&&(xhr.status == 200)) affiche("etat","chargée...");
if ((xhr.readyState==3)&&(xhr.status == 200)) affiche("etat","en cours de traitement...");
if ((xhr.readyState==4)&&(xhr.status == 200)) {
var docTXT= xhr.responseText;
affiche("etat","terminé");
affiche("affiche",docTXT)
}
}
</script>
</head>
<body>
<p>
<a href="javascript:Test_Pseudo();">Cliquez-moi toujours !</a>
</p>
<div id="etat"></div>
<div id="affiche"></div>
</body>
</html> |
Partager