Buon giorno a tutti.
Sono registrato ad un sito che offre la possibilità di estrapolare informazioni da alcuni file xml per gli sviluppatori.
I file xml contengono informazioni del proprio account e possono essere raggiunti solamente facendo ciò che viene indicato dal sito stesso, ovvero:
Sito
Inoltre, questi file xml possono essere visti solamente se viene effettuato il login tramite metodo post con le variabili ilogin e ipassword. Appena effettuato il login viene creata una variabile che si chiama "errorno" che dovrebbe restituire 0 se il login è giusto. Se il login è avvenuto correttamente crea un cookie XMLSESSID.
Lo script che utilizzo è il seguente:
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=iso-8859-1" />
<title>Juniors - Ajax e file XML</title>
<style type="text/css" media="all">
#contenuto { border: 3px double #cc0000; background-color: #ffeeee; padding: 3px; width: 400px; }
.id { font: 14px Verdana; font-weight: bold; color: #cc0000; }
.name { font: 12px Verdana; font-weight: bold; }
.skill { font: 10px Verdana; text-align:justify; }
.weeks { font: 10px Verdana; text-align:justify; }
</style>
</head>
<body>
<script type="text/javascript" language="javascript">
var http_request = false;
function esegui_richiesta(indirizzo) {
http_request = false;
if (window.XMLHttpRequest) { // browser Mozilla
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) http_request.overrideMimeType('text/xml');
} else if (window.ActiveXObject) { // browser Microsoft InternetExplorer
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('ERRORE : Impossibile inizializzare AJAX');
return false;
}
http_request.onreadystatechange = processa_risposta;
http_request.open("GET", indirizzo, true);
http_request.send(null);
}
function processa_risposta() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
txt = '';
var xmldoc = http_request.responseXML;
var artlist = xmldoc.getElementsByTagName('junior');
for (i=0;i<artlist.length;i++) {
art = artlist.item(i);
txt += '<div class="' + art.childNodes.item(0).nodeName + '">' + art.childNodes.item(0).nodeName + ': ' + art.childNodes.item(0).text + '</div>';
txt += '<div class="' + art.childNodes.item(0).nodeName + '">' + art.childNodes.item(1).nodeName + ': ' + art.childNodes.item(1).text + '</div>';
txt += '<div class="' + art.childNodes.item(0).nodeName + '">' + art.childNodes.item(2).nodeName + ': ' + art.childNodes.item(2).text + '</div>';
txt += '<div class="' + art.childNodes.item(0).nodeName + '">' + art.childNodes.item(3).nodeName + ': ' + art.childNodes.item(3).text + '</div>';
txt += '<div class="' + art.childNodes.item(0).nodeName + '">' + art.childNodes.item(4).nodeName + ': ' + art.childNodes.item(4).text + '</div>';
txt += '
';
}
elemento = document.getElementById('contenuto');
elemento.innerHTML = txt;
} else {
alert('Si è verificato un problema con la risposta AJAX');
}
}
}
</script>
<div style="font: 12px Verdana;">
<span style="cursor: pointer; text-decoration: underline" onclick="esegui_richiesta('juniors.xml')">Carica dati XML</span>
</div>
<div id="contenuto">
<div class="id">ID: </div>
<div class="name">Giocatore: </div>
<div class="skill">Livello: </div>
<div class="weeks">Settimane: </div>
</div>
</body>
</html>
In questo caso non avviene il login. Lo faccio a mano sul sito e mi scarico in locale il file xml. In questo modo il mio script funziona alla grande.
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=iso-8859-1" />
<title>Juniors - Ajax e file XML</title>
<style type="text/css" media="all">
#contenuto { border: 3px double #cc0000; background-color: #ffeeee; padding: 3px; width: 400px; }
.id { font: 14px Verdana; font-weight: bold; color: #cc0000; }
.name { font: 12px Verdana; font-weight: bold; }
.skill { font: 10px Verdana; text-align:justify; }
.weeks { font: 10px Verdana; text-align:justify; }
</style>
</head>
<body>
<script type="text/javascript" language="javascript">
var http_request = false;
function esegui_richiesta(indirizzo) {
http_request = false;
if (window.XMLHttpRequest) { // browser Mozilla
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) http_request.overrideMimeType('text/xml');
} else if (window.ActiveXObject) { // browser Microsoft InternetExplorer
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('ERRORE : Impossibile inizializzare AJAX');
return false;
}
http_request.onreadystatechange = processa_risposta;
http_request.open("POST", indirizzo, true);
--> http_request.setRequestHeader(); <-- SE QUALCUNO ME LO SPIEGA è MEGLIO
http_request.send("ilogin=myusername&ipassword=mypassword");
}
function processa_risposta() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
txt = '';
var xmldoc = http_request.responseXML;
var artlist = xmldoc.getElementsByTagName('junior');
for (i=0;i<artlist.length;i++) {
art = artlist.item(i);
txt += '<div class="' + art.childNodes.item(0).nodeName + '">' + art.childNodes.item(0).nodeName + ': ' + art.childNodes.item(0).text + '</div>';
txt += '<div class="' + art.childNodes.item(0).nodeName + '">' + art.childNodes.item(1).nodeName + ': ' + art.childNodes.item(1).text + '</div>';
txt += '<div class="' + art.childNodes.item(0).nodeName + '">' + art.childNodes.item(2).nodeName + ': ' + art.childNodes.item(2).text + '</div>';
txt += '<div class="' + art.childNodes.item(0).nodeName + '">' + art.childNodes.item(3).nodeName + ': ' + art.childNodes.item(3).text + '</div>';
txt += '<div class="' + art.childNodes.item(0).nodeName + '">' + art.childNodes.item(4).nodeName + ': ' + art.childNodes.item(4).text + '</div>';
txt += '
';
}
elemento = document.getElementById('contenuto');
elemento.innerHTML = txt;
} else {
alert('Si è verificato un problema con la risposta AJAX');
}
}
}
</script>
<div style="font: 12px Verdana;">
<span style="cursor: pointer; text-decoration: underline" onclick="esegui_richiesta('http://online.sokker.org/xml/juniors.xml')">Carica dati XML</span>
</div>
<div id="contenuto">
<div class="id">ID: </div>
<div class="name">Giocatore: </div>
<div class="skill">Livello: </div>
<div class="weeks">Settimane: </div>
</div>
</body>
</html>
In questo caso non ho proprio idea di come possa funzionare. Non funziona ed ovviamente ho pochissima esperienza in XMLDOM.