dato un file html
codice:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" language="javascript">
var http_request = false;
function makeRequest(url) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
http_request.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
http_request.onreadystatechange = alertContents;
http_request.open('GET', url, true);
http_request.send(null);
}
function alertContents() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
var pippo = http_request.responseText;
//alert(http_request.responseText);
} else {
alert('There was a problem with the request.');
}
}
if (pippo) return pippo;//alert (pippo);
}
</script>
</head>
<body>
<span
style="cursor: pointer; text-decoration: underline"
onclick="alert(send_request('test.php?array='));">
Make a request
</span>
</body>
</html>
e un file php
Codice PHP:
<?
$array_mio=array("A"=>array("X1"=>"A_uno","X2"=>"A_due"),
"B"=>array("X1"=>"B_uno","X2"=>"B_due"),
"C"=>array("X1"=>"C_uno","X2"=>"C_due"),
"D"=>array("X1"=>"D_uno","X2"=>"D_due"),
"E"=>array("X1"=>"E_uno","X2"=>"E_due"),
"F"=>array("X1"=>"F_uno","X2"=>"F_due"),
"G"=>array("X1"=>"G_uno","X2"=>"G_due"),
"H"=>array("X1"=>"H_uno","X2"=>"H_due"),
"I"=>array("X1"=>"I_uno","X2"=>"I_due"),
"L"=>array("X1"=>"L_uno","X2"=>"L_due"),
"M"=>array("X1"=>"M_uno","X2"=>"M_due"),
"N"=>array("X1"=>"N_uno","X2"=>"N_due"),
"O"=>array("X1"=>"O_uno","X2"=>"O_due"),
"P"=>array("X1"=>"P_uno","X2"=>"P_due"),
"Q"=>array("X1"=>"Q_uno","X2"=>"Q_due"));
if (isset($_GET['nome'])) echo "Mirko";
if (isset($_GET['nick'])) echo "dottwatson";
if (isset($_GET['age'])) echo "00";
if (isset($_GET['array'])) $val = arr2xml ($array_mio);
if ($val)echo $val;
function arr2xml($array)
{
include('assoc_array2xml.php');
$converter= new assoc_array2xml;
$string=$converter->array2xml($array);
return $string;
}
function xml2arr($code)
{
include('assoc_array2xml.php');
$converter= new assoc_array2xml;
$string=$converter->xml2array($code);
return $string;
}
?>
perchè la variabile non mi torna indietro? eppure l' xml viene generato correttamente se faccio un alert all' interno del ciclo alertContents()