Bonjour
J'ai fait une page très simple pour mon premier test avec Ajax.
La voilà :
Etrangement, le premier write() (qui affiche "Bienvenue") ne s'exécute pas si je mets le code qui le suit. Si je le mets tout seul, ça marche... Bon déjà, je ne comprends pas.Code:
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 <html> <head> <title> Ajax power </title> </head> <body> <script language="Javascript"> <!-- var xhr_object = null ; window.document.write('Bienvenue'); if(window.XMLHttpRequest) // firefox { xhr_object = new XMLHttpRequest(); } else if (window.ActiveXObject) { xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); } else { alert("Ajax not supported"); return ; } xhr_object.open("GET","http://mnasrawin.free.fr/index.php", true); xhr_object.onreadystatechange = function() { if(xhr_object.readyState == 1) window.document.write("Loading..."); else window.document.write(xhr_object.responseText); } xhr_object.send(null); // --> </script> </body> </html>
Ensuite, le problème avec cette page, c'est que RIEN ne s'affiche, j'ai une page blanche seulement ... C'est pas supposé m'afficher au moins "Loading..." ?
Merci
Nas'
