Ver Mensaje Individual
  #1 (permalink)  
Antiguo 24/06/2014, 16:47
Avatar de Italico76
Italico76
 
Fecha de Ingreso: abril-2007
Mensajes: 3.303
Antigüedad: 17 años
Puntos: 292
Bug en firebug ?

Hola gente!

Tratando de corregir unas funciones que habia escrito para manejo de Ajax me encontre con un problema para mi indescifrable...... un extraño comportamiento del "Inspect Element" tanto de Chrome como de Firefox.

Me dice primero que un objeto Ajax tiene status:0 y cuando lo inspecciono dice que tiene status:200

Por otro lado "copio" el objeto a otra variable (ob = aR) y cuando la miro dice algo completamente distinto!

Alguien entiende que esta pasando ? y por que tanto Chrome con Firefox observan este comportamiento ?



http://i1353.photobucket.com/albums/...psc8991cb4.png

Código Javascript:
Ver original
  1. <html>
  2. <body>
  3.  
  4. <form name="personal" action="../pruebas/ver_dump $_REQUEST.php" id="personal1">
  5.     Edad:
  6.     <input type="text" id="edad" /> <br />
  7.     Peso:
  8.     <input type="text" id="peso"  /><br />
  9.     Sexo:
  10.     <select id="sexo">
  11.         <option value="MASCULINO">M</option>
  12.         <option value="FEMENINO">F</option>
  13.     </select>  
  14. </form>
  15.  
  16. <div id="outputAjax">Resultados del lado del servidor</div>
  17.  
  18.  
  19. <script>
  20.  
  21. var edad_el     = document.getElementById('edad'),
  22.     peso_el     = document.getElementById('peso'),
  23.     sexo_el     = document.getElementById('sexo'),
  24.     frm         = document.getElementById('personal1'),
  25.     outputAjax  = document.getElementById('outputAjax');
  26.  
  27.  
  28.     onreadystatechangeHandler = function(aR)
  29.     {
  30.         ob = aR;
  31.        
  32.         if(ob.readyState == 4  && ob.status == 200 ){  
  33.             console.log(ob.responseText);
  34.             outputAjax.innerHTML = ob.responseText;
  35.         }else{
  36.             console.log ('readyState: '+ob.readyState+' y status: '+ob.status);
  37.             console.log (ob);
  38.         }  
  39.        
  40.            
  41.     };     
  42.  
  43.     function ajaxRequestObjectBuilder()
  44.     {    
  45.     var object;
  46.    
  47.     try{
  48.         // Opera 8.0+, Firefox, Safari
  49.         object = new XMLHttpRequest();
  50.     } catch (e){
  51.         // Internet Explorer
  52.         try{
  53.             object = new ActiveXObject("Msxml2.XMLHTTP");
  54.         } catch (e) {
  55.             try{
  56.                 object = new ActiveXObject("Microsoft.XMLHTTP");
  57.             } catch (e){                
  58.                 alert("Error en Ajax");
  59.                 return false;
  60.             }
  61.         }
  62.        
  63.     }          
  64.     return object;
  65.     }
  66.  
  67. function ajaxByGet()
  68. {
  69.  
  70. var ajaxRequest = ajaxRequestObjectBuilder();
  71.  
  72.     // registro funcion para Ajax
  73.     ajaxRequest.onreadystatechange = onreadystatechangeHandler(ajaxRequest);
  74.     //console.log(ajaxRequest);
  75.  
  76. var edad = edad_el.value,
  77.     peso = peso_el.value,
  78.     sexo = sexo_el.value;
  79.  
  80.     var params = "?edad=" + edad + "&peso=" + peso + "&sexo=" + sexo;
  81.     ajaxRequest.open("GET", frm.action + '?' + params, true);
  82.     ajaxRequest.send(null);
  83. }
  84.  
  85.  
  86. // Registro cambios en elementos deel formulario: onChange
  87. document.getElementById('personal1').addEventListener("change", function (event)
  88. {
  89.     var tagname = event.target.tagName;
  90.    
  91.     if (tagname == 'SELECT')
  92.     {
  93.         ajaxByGet();        
  94.     }
  95. });
  96.  
  97. // Registro cambios en elementos deel formulario: onKeyup
  98. document.getElementById('personal1').addEventListener("keyup", function (event)
  99. {
  100.     var tagname = event.target.tagName;
  101.    
  102.     if (tagname == 'INPUT' || tagname == 'TEXTAREA')
  103.     {
  104.         ajaxByGet();        
  105.     }
  106. });
  107.  
  108. </script>
  109.  
  110.  
  111. </body>
  112. </html>
  113. </html>

y la parte que estaba debugueando es esta:

Código Javascript:
Ver original
  1. onreadystatechangeHandler = function(aR)
  2.     {
  3.         ob = aR;
  4.        
  5.         if(ob.readyState == 4  && ob.status == 200 ){  
  6.             console.log(ob.responseText);
  7.             outputAjax.innerHTML = ob.responseText;
  8.         }else{
  9.             console.log ('readyState: '+ob.readyState+' y status: '+ob.status);
  10.             console.log (ob);
  11.         }              
  12.     };

Desde ya muchas gracias
__________________
Salu2!