Ciao.
Questo è lo snippet:
Codice PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="JavaScript" type="text/JavaScript">
var req = null;
function processReqChange() {
if (req.readyState == 4 && req.status == 200 ) {
xml= req.responseXML.documentElement;
/* Dichiaro links global */
links= new Array();
var item= xml.getElementsByTagName('item');
for(var i=0;i<item.length;i++){
links[i]= new Array();
for(var y=0;y<item[i].childNodes.length;y++){
if(item[i].childNodes[y].tagName=='id' || item[i].childNodes[y].tagName=='title'){
links[i].push(item[i].childNodes[y].firstChild.data);
}
}
}
}
//alert(links);
}
function loadUrl( url ) {
if(window.XMLHttpRequest) {
try { req = new XMLHttpRequest();
} catch(e) { req = false; }
} else if(window.ActiveXObject) {
try { req = new ActiveXObject('Msxml2.XMLHTTP');
} catch(e) {
try { req = new ActiveXObject('Microsoft.XMLHTTP');
} catch(e) { req = false; }
} }
if(req) {
req.onreadystatechange = processReqChange;
req.open('GET', url, true);
req.send('');
}
}
function test()
{
alert(links);
}
loadUrl('xml/items.xml');
window.onload=function(){
test();
}
</script>
</head>
<body>
<body>
</body>
</html>
Praticamente faccio caricare un file xml
per recuperare i valori dei tag id e title
e metto tutti i valori in un array che dichiaro
globale all'interno di processReqChange e fino
qui no problem.
Dopo aver costruito l'array lo vorrei utilizzare
per implementare un sistema di paging per
permettere all'utente una veloce scorsa di tutti
i titoli presenti nel sito.
Il problema è che l'array links non è
visibile all'interno di test come mi aspetterei.
Altra cosa che non riesco a capire e che su Opera
funzionicchia su FF manco pu c......
Ho l'impressione di fare un errore di fondo
ma non riesco a venirne fuori mi date una
mano