mohican Posted May 14, 2009 at 07:21 PM Report #264218 Posted May 14, 2009 at 07:21 PM Boas, estou farto de bater com a cabeça nisto... pode ser que alguem me consiga ajudar tenho um xml com o seguinte conteudo: <cds> <cd> <titulo>ACDC</titulo> <data>yada yada</data> <obs>mais yada yada</obs> </cd> </cds> e estou a tentar ir buscar o titulo, data e obs o que tenho é o seguinte var xml = ajax.responseXML.document.element; var y = xml.getElementsByTagName("cd")[0].childNode[1].firstChild.nodeValue; que provavelmente está mal, mas de qq das maneiras devolve-me o valor titulo ? se modificar para childNode[2] não devolve nada.. helpp, deveme tar a falar qq coisa 😄 😄 segue codigo todo: var ajax; function change() { var x = "1"; ajax = criarXmlHttpRequest(x); mostrarContent(x); } function criarXmlHttpRequest(x) { // Se IE7//FF/Opera // alert(selec); if (window.XMLHttpRequest) { var meuAjax = new XMLHttpRequest(); //alert(meuAjax); return meuAjax; } else if (window.ActiveXObject)// Se IE6 / IE5 { //versoes do xml var versoes = ["MSXML2.XmlHttp.6.0", "MSXML2.XmlHttp.3.0" ]; for (var i = 0; i < versoes.length; i++) { try { var meuAjax = new ActiveXObject(versoes[i]); return meuAjax; } catch(error) { alert ("erro"); // nao faz nada. para detectar erros: alert(error) } } } else //excepcao { return null; } } function mostrarContent (x) { switch(x) { case("1"): { ajax.open("GET", "ajaxteste.xml", false); ajax.send(null) if (ajax.status == 200); { //alert(ajax.responseText); var xml = ajax.responseXML.documentElement; //window.document.write(ajax.responseText); } //document.getElementById("um").innerHTML = ajax.responseText; var y = xml.getElementsByTagName('cliente')[0]; var o = y.childNodes[0].childNodes[0].nodeValue; alert(o); //var y = xml.getElementsByTagName('cliente')[0].childNodes[0].firstChild.length; break; } } }
mohican Posted May 16, 2009 at 06:46 PM Author Report #264676 Posted May 16, 2009 at 06:46 PM BEm, já resolvi o problema... faltava-me um onreadystatechange lol entretanto ja consigo ir buscar o xml feito em php e selecionar a info que quero .. ajax is a powerful shit 😁
AndreLC Posted August 7, 2011 at 11:55 PM Report #406710 Posted August 7, 2011 at 11:55 PM Boas, Como estás a fazer para a partir de PHP ler os dados de um XML? Obrigado. Cumps echo ($knowledge != $sharing) ? "Serves no purpose!" : "Thank you for your help. It was very precious.";
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now