PDA

View Full Version : [AJAX] Richiesta GET di un file XML


vv1984
12-06-2008, 10:10
Ciao a tutti, sto provando a fare una richiesta GET su un file XML,
ma non ottengo nessuna risposta dal server. Ho provato a debuggare
il codice ovunque, ed ho notato che dopo aver ottenuto il readyState==4
non succede pił nulla. Non riesco nemmeno a verificare se mi venga ritornato un valore di status diverso o uguale a 200.

Ringraziandovi in anticipo per la collaborazione, provo a postare il codice nella speranza che possiate aiutarmi:



var xmlDocument;
var xmlHttp;


function getRichiesta()
{
xmlHttp = getXmlHttpObject();

xmlHttp.open("GET","http://miosito.com/miofile.xml",true);
xmlHttp.onreadystatechange= function()
{
if (xmlHttp.readyState==4)
{
if(xmlHttp.status==200 || xmlHttp.status==304)
{
xmlDocument=xmlHttp.responseXML;
}
}
};
xmlHttp.send(null);

alert(xmlDocument.getElementsByTagName("descrizione")[0].childNodes[0].nodeValue);

}

function getXmlHttpObject()
{
var objXMLHttp=null;
if (window.XMLHttpRequest)
{
objXMLHttp = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
return objXMLHttp;
}