Bonjour,
J'utilise sur ma page le script suivant pour remplir 2 "div" différents :
Et j'appelle mes 2 includes comme ça :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <script type='text/JavaScript'> var xhr = null; function getXhr() { if(window.XMLHttpRequest)xhr = new XMLHttpRequest(); else if(window.ActiveXObject) { try{ xhr = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } } else { alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); xhr = false; } } function ShowFrame(page) { getXhr() xhr.onreadystatechange = function() { if(xhr.readyState == 4 && xhr.status == 200) { document.getElementById('page').innerHTML=xhr.responseText; } } xhr.open("GET","ajax.php?page="+page,true); xhr.send(null); } function ShowAlbum(page) { getXhr() xhr.onreadystatechange = function() { if(xhr.readyState == 4 && xhr.status == 200) { document.getElementById('album').innerHTML=xhr.responseText; } } xhr.open("GET","ajax2.php?page="+page,true); xhr.send(null); } function ShowPage(page) { ShowFrame(page); ShowAlbum(page); } </script>
<div id="page"></div> <div id="album"></div>
(ils ne sont pas placés au même endroit de la page, d'où mon besoin d'avoir deux fonctions ShowFrame(page) et ShowAlbum(page).
Mon fichier ajax.php contient :
Et ajax2.php :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 <?php $page=$_GET['page']; if($page==2)require '2.html'; else if($page==3)require '3.html'; else if($page==4)require '4.html'; else if($page==5)require '5.html'; else require '1.html'; ?>
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 <?php $page=$_GET['page']; if($page==2)require 'album_2.html'; else if($page==3)require 'album_3.html'; else if($page==4)require 'album_4.html'; else if($page==5)require 'album_5.html'; else require 'album_1.html'; ?>
Voilà le problème :
Quand je charge la page, je vois "album" aux deux endroits au lieu de "page" et "album". Quand je recharge la page, je vois bien comme je veux "page" et "album", quand je charge une autre page, je vois 2 "albums". Assez aléatoire en faite.
Je pense que ça vient du script que j'ai posté plus haut mais je n'ai pas assez de connaissances pour trouver le problème.
Merci de m'aider !
Partager