Bonjour,
Je suis en train de dévelloper une galerie de photos avec une sélection, je génère un fichier XML à partir de la base de données. la variable objxhr.responseXML me retourne "null"(voir alert(arg))( en rouge ), voici les sources javascript et php :
Javascript : galerie.js
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// ---------------------------------
// Galerie === place_diapo()
// ---------------------------------
function charge_galerie(arg) {
	objxhr = xhr_connect()
	if (objxhr) {
		objxhr.onreadystatechange = function() {
			if (objxhr.readyState == 4) {
				if (objxhr.status == 200) {	
					//alert(objxhr.responseText)
					reset_galerie()	
					retour = objxhr.responseXML
					place_galerie(retour)
				}
			}
		}
		sql = "ch_img_rubId=" + arg;
		objxhr.open("POST", "charge_galerie.php", true)
		objxhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		objxhr.send(sql)
 
	} else { 
		alert("Soucis d'xmlHttpRequest") 
	}
}
function reset_galerie() {
	pc = document.getElementById('planche-contact')
	while (pc.firstChild) {
		pc.removeChild(pc.firstChild)
	}
}
function place_galerie(arg) {
	diapos = arg.getElementsByTagName('image')
	nb_diapo = diapos.length
	for (i=0; i<nb_diapo;i++) {
		dia_temp = diapos[i]		
		img = dia_temp.getElementsByTagName('ch_img_fichier')[0].firstChild.nodeValue
		infos = dia_temp.getElementsByTagName('ch_img_id')[0].firstChild.nodeValue
		folder = dia_temp.getElementsByTagName('ch_img_rubId')[0].firstChild.nodeValue
		orientation = dia_temp.getAttribute('orientation')
		place_diapo(img, infos, folder, orientation)
	}
}
// ---------------------------------
// Diapositives
// ---------------------------------
function place_diapo(arg, src, folder, orientation) {
	pc =document.getElementById('planche-contact')
	div = document.createElement('div')
	img = document.createElement('img')
	img.alt = folder
	img.className = orientation
	img.src = "images/"+folder+"/thumbs/"+arg
	div.appendChild(img)
	div.src = src
	div.onclick = function() {
		//alert(this.src)
		searchInfos(this.src)
	}
	pc.appendChild(div)
}
// ---------------------------------
// OBJET XML HTTP Request
// ---------------------------------
function xhr_connect() {
	xhr = false
	if (window.XMLHttpRequest) {
		xhr = new XMLHttpRequest
	} else if (window.ActiveXObject) {
		reussi = false
		iexhr = new Array("Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0",
						"Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP",
						"Microsoft.XMLHTTP")
		for (i=0; i<iexhr.length && ! reussi; i++) {
			try {
				xhr = new ActiveXObject(iexhr[i])
			} catch(e) {}
		}
	}
	return xhr; 
}
PHP : charge_galerie.php
Code php : 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
<?php
        include_once 'Scripts/connect.php';
	header('Content-Type: text/xml');
	header("Cache-Control: no-cache, must-revalidate");
	header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");	
 
	// Paramètre
	$ch_img_rubId = $_POST['ch_img_rubId'];
 
	// Sélection et exécution; 
	$sql = "SELECT * FROM images WHERE ch_img_rubId = '$ch_img_rubId'";
	$xml = '<?xml version="1.0" encoding="UTF-8"?>';
	$cat = $DB->query($sql);
 
	if ($cat->RowCount() != 0) :
		$xml .= '<images>';
		while ($d=$cat->fetch(PDO::FETCH_OBJ)) :
			$xml .= '<image orientation='.$d->ch_img_orientation.'">';		
				$xml .= '<ch_img_fichier>'.$d->ch_img_fichier.'</ch_img_fichier>';
				$xml .= '<ch_img_id>'.$d->ch_img_id.'</ch_img_id>';
				$xml .= '<ch_img_rubId>'.$d->ch_img_rubId.'</ch_img_rubId>';
			$xml .= '</image>';
 
 
		endwhile;
		$xml .= '</images>';
	else :
		$xml .= "<erreur>Il semble qu'il n'y a pas d'image pour la catégorie " .$ch_img_rubId.".</erreur>";
	endif;
		echo $xml;
?>
Tant qu'à faire, je mets également le script de connexion à la BDD : connect.php
<?php
	try {
		$DB = new PDO('mysql:host=localhost;dbname=galerie', 'root', '', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'')); 
		$DB->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	}
	catch (PDOException $e) {
    		echo 'Échec lors de la connexion à la base de données';
	}
?>
Je suis sous windows 10, wampserver 3.0, PHP 7.0

alert(objxhr.reponseText) me donne bien mon script XML mais alert(objxhr.responseXML) me retourne "null"
J'ai beau cherhé ou se trouve l'erreur, mais en vain