Jump to content

Recommended Posts

Posted

Boas, estou farto de bater com a cabeça nisto... pode ser que alguem me consiga ajudar  :wallbash:

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;
		}
}
}
Posted

BEm, já resolvi o problema... faltava-me um onreadystatechange lol  :wallbash: entretanto ja consigo ir buscar o xml feito em php e selecionar a info que quero ..

ajax is a powerful shit  😁

  • 2 years later...
Posted

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.";

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.