Ver Mensaje Individual
  #7 (permalink)  
Antiguo 01/11/2012, 07:36
Avatar de emprear
emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 16 años, 10 meses
Puntos: 1567
Respuesta: AJAX, el debugger me dice que no puede "leer el valor de ReadyState"

A ver, aparentemente estás leyendo un xml
Y no es necesario que utilices 3 funciones


Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <title>titulo</title>
  5. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  6.  
  7. <script type="text/javascript">
  8. //<![CDATA[
  9.  
  10. // creas el objeto Ajax
  11. function ajaxFunction() {
  12. var xmlHttp;
  13. try {
  14. xmlHttp=new XMLHttpRequest();
  15. return xmlHttp;
  16. } catch (e) {
  17. try {
  18. xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  19. return xmlHttp;
  20. } catch (e) {
  21. try {
  22. xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  23. return xmlHttp;
  24. } catch (e) {
  25. alert("Tu navegador no soporta AJAX!");
  26. return false;
  27. }}}
  28. }
  29.  
  30.  
  31. function LlamadaAjaxValidarNombre() {
  32.     // llamas a ajax
  33. var ajax;
  34. ajax = ajaxFunction();
  35. var url = "validarnombre.xml";
  36. ajax.open("GET", url, true);
  37. ajax.onreadystatechange=function(){
  38.  
  39. if(ajax.readyState == 4) {
  40.     if(ajax.status == 200) {
  41.     var nodoRespuesta = ajax.responseXML.getElementsByTagName("title")[0];
  42.     var textoRespuesta = nodoRespuesta.childNodes[0].nodeValue;
  43.     document.getElementById('respuestaphp').innerHTML = textoRespuesta;
  44. }
  45. }
  46.  
  47.  
  48. }
  49.      
  50. ajax.send(null);
  51. }
  52.  
  53. //]]>
  54.  
  55. </head>
  56. <button onclick="LlamadaAjaxValidarNombre();">xxx</button>
  57. <div id="respuestaphp">
  58. </div>
  59. </body>
  60. </html>

Luego aqui
var textoRespuesta = nodoSaludo.childNodes[0].nodeValue;
nodoSaludo no está definido, habrás querido poner nodoRespuesta

usé este xml


Código XML:
Ver original
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!-- Edited by XMLSpy® -->
  3. <catalog>
  4.     <cd>
  5.         <title>Empire Burlesque</title>
  6.         <artist>Bob Dylan</artist>
  7.         <country>USA</country>
  8.         <company>Columbia</company>
  9.         <price>10.90</price>
  10.         <year>1985</year>
  11.     </cd>
  12. </catalog>



Saludos
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.