Ver Mensaje Individual
  #14 (permalink)  
Antiguo 12/12/2006, 07:01
Avatar de juank30
juank30
 
Fecha de Ingreso: julio-2005
Mensajes: 29
Antigüedad: 18 años, 9 meses
Puntos: 0
Se que esta solucionado pero...

Hola según dicen en este foro el problema de trabajar con archivos XML en IE se soluciona con un Header, pero estoy hace unos dias que no puedo hacer correr este codigo en IE, es el mismo problema que se ha tenido desde el comienzo el responseXML.documentElement devuelve null y estoy poniendo la cabecera en el archivo php, aqui les pongo todo el codigo para que lo prueben, por favor diganme donde me equivoco:

Archivo html (books.html):
Código HTML:
<html>
  <head>
    <title>AJAX Foundations: JavaScript and XML</title>
    <script type="text/javascript" src="books.js"></script>
  </head>
  <body onload="process()">
    Server, tell me your favorite books!
    <br/>
    <div id="myDivElement" />
  </body>
</html> 
Su javaScript (books.js):

Código:
var xmlHttp = createXmlHttpRequestObject();

function createXmlHttpRequestObject(){
  var xmlHttp;
  if (window.XMLHttpRequest) { // Mozilla, Safari,...
		xmlHttp = new XMLHttpRequest();
  if (xmlHttp.overrideMimeType) {
		xmlHttp.overrideMimeType('text/xml');
	}
	} else if (window.ActiveXObject) { // IE
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
  }
  return xmlHttp;
}

function process(){
  if (xmlHttp){
    try{
      xmlHttp.open("GET", "respondo.php", true);
      xmlHttp.onreadystatechange = handleRequestStateChange;
      xmlHttp.send(null);
    }
    catch (e){
      alert("Can't connect to server:\n" + e.toString());
    }
  }
}

function handleRequestStateChange(){ 
  if (xmlHttp.readyState == 4){
    if (xmlHttp.status == 200){
      try{
        handleServerResponse();
      }
      catch(e){
        alert("Error reading the response: " + e.toString());
      }
    } 
    else{
      alert("There was a problem retrieving the data:\n" + xmlHttp.statusText);
    }
  }
}

function handleServerResponse(){
  xmlRoot = xmlHttp.responseXML.documentElement;
  titleArray = xmlRoot.getElementsByTagName("title");
  isbnArray = xmlRoot.getElementsByTagName("isbn");
  var html = "";  
  for (var i=0; i<titleArray.length; i++)
    html += titleArray.item(i).firstChild.data + ", " + isbnArray.item(i).firstChild.data + "<br/>";
  myDiv = document.getElementById("myDivElement");
  myDiv.innerHTML = "Server says: <br />" + html;
}
Y el archivo .php que responde (respondo.php):

Código PHP:
<?
header
("Content-Type: text/xml"); 

echo 
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";
echo 
"<response>";
echo 
"  <books>";
echo 
"    <book>";
echo 
"      <title>";
echo 
"        Building Reponsive Web Applications with AJAX and PHP";
echo 
"      </title>";
echo 
"      <isbn>";
echo 
"        1-904811-82-5";
echo 
"      </isbn>";
echo 
"    </book>";
echo 
"    <book>";
echo 
"         <title>";
echo 
"        Beginning PHP 5 and MySQL E-Commerce: From Novice to Professional";
echo 
"      </title>";
echo 
"      <isbn>";
echo 
"        1-59059-392-8";
echo 
"      </isbn>";
echo 
"    </book>";
echo 
"  </books>";
echo 
" </response>";
?>
Muchas Gracias.
__________________
.:Ju@nK:.