[AJAX] Pas de réponse avec Firefox
Bonjour,
J'essaye de mettre à jour dynamiquement un tableau.
Voici le code que j'utilise :
fichier php:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
header("Content-type:application/json");
$file = 'fichier.csv';
$handle = fopen($file, 'r');
$tb_php=array();
$i = 0;
while (!feof($handle))
{
$ligne = fgets($handle, 1024);
$el = explode(";",$ligne);
for($j=0;$j<sizeof($el);$j++)
{
$el[$j]=trim($el[$j]);
if($el[$j]!="") { $tb_php[$i][$j]=$el[$j];}
}
$i++;
}
fclose($handle);
json_encode($tb_php); |
fichier javascript :
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
|
var arr= new Array ();
function ajax(type)
{
var xhr;
try { xhr = new ActiveXObject('Msxml2.XMLHTTP'); }
catch (e)
{
try { xhr = new ActiveXObject('Microsoft.XMLHTTP'); }
catch (e2)
{
try { xhr = new XMLHttpRequest(); }
catch (e3) { xhr = false; }
}
}
xhr.onreadystatechange = function()
{
if(xhr.readyState == 4)
{
if(xhr.status == 200)
{
alert (xhr.responsetext);
arr=eval(xhr.responsetext);
}
else
{
alert("Error code " + xhr.status);
}
}
};
xhr.open("GET", "ajax.php", true);
xhr.send(null);
} |
Ce code marche très bien avec IE mais pas de responsetext avec Firefox...
Que puis-je tester pour résoudre le pb? (j'ai pas l'habitude d'utiliser ajax et encore moins un tableau JSON et là j'ai plus trop d'idées : j'ai essayé de modifier l'entête php sans succès...)