Ver Mensaje Individual
  #1 (permalink)  
Antiguo 19/03/2014, 15:22
Avatar de satjaen
satjaen
 
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 8 meses
Puntos: 10
Error xml is null

Hola, tengo este código y me da el siguiente error:

Código Javascript:
Ver original
  1. TypeError: xml is null
  2. dato=xml.getElementsByTagName('datos');

Este el código:

Código Javascript:
Ver original
  1. if($minimos == '1' and $existencias == '0') {
  2.  
  3.  
  4. echo "<script language='JavaScript'>
  5.                        
  6.  var recambio = document.forms['form4'].elements['recambio'];
  7.  
  8.  
  9.        
  10.             respuesta =confirm('¿Atención, articulo en mínimos desea pedirlo?');
  11.    
  12.                    if (respuesta){
  13.        
  14.                 if (window.XMLHttpRequest)
  15.         {
  16.             xmlhttp=new XMLHttpRequest();
  17.         }
  18.         else
  19.         {
  20.             xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
  21.         }  
  22.         xmlhttp.open('GET', 'cons_minimos.php?id=' + recambio.value, false);
  23.         xmlhttp.send();    
  24.  
  25.        if (xmlhttp.readyState==4 && xmlhttp.status==200)      
  26.        {
  27.            var xml = xmlhttp.responseXML;
  28.            dato=xml.getElementsByTagName('datos');
  29.            if(dato[0].firstChild.nodeValue=='1')
  30.            {
  31.                num_user=xml.getElementsByTagName('numusuario');
  32.                
  33.                if (confirm('¡Recambio existente!¿Desea eliminarlo?'))
  34.                {
  35.                  
  36.                    alert('¡Eliminado!');   
  37.                 }
  38.                else
  39.                {
  40.                     window.location.href = '';   
  41.                }
  42.            }
  43.            if(dato[0].firstChild.nodeValue=='0')
  44.            {          
  45.                      
  46.      document.getElementById('form4').submit();  
  47.  
  48.             }        
  49.                          
  50.                          
  51.             }
  52.         }
  53.        
  54.    
  55.        
  56. </script>";
  57.  
  58.  
  59. }else{
  60.    
  61.    
  62.    
  63.     return false;
  64.    
  65.    
  66. }


cons_minimos.php

Código Javascript:
Ver original
  1. <?php
  2. $xml="<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";
  3. $xml.="<respuesta>\n";
  4. $con=mysql_connect ("localhost","","");
  5. mysql_select_db("Avisoswed",$con);
  6. $recambio = isset($_GET['id']) ? $_GET['id']:"";
  7. $sql="SELECT recambio FROM material_pendiente WHERE recambio ='".$recambio."'";
  8. $datos=mysql_query($sql,$con);
  9.      while ($row=mysql_fetch_array($datos)){
  10.            $recambio=$row['recambio'];
  11.      }
  12.      $rows = mysql_num_rows($datos);
  13. if ($rows>0)
  14. {
  15.     $xml.="<datos><![CDATA[1]]></datos>\n";
  16.     $xml.="<numusuario><![CDATA[".$recambio."]]></numusuario>\n";
  17. }
  18. else
  19. {
  20.  
  21.    $xml.='<datos><![CDATA[0]]></datos>\n';
  22.   $xml.="<numusuario><![CDATA[".$recambio."]]></numusuario>\n";
  23.    
  24. }
  25. $xml.="</respuesta>\n";
  26. echo $xml;
  27. ?>

La respuesta de cons_minimos.php
Código Javascript:
Ver original
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <respuesta>
  3. <datos><![CDATA[1]]></datos>
  4. <numusuario><![CDATA[119208]]></numusuario>
  5. </respuesta>

Muchas gracias !!!!!!!!!!

Última edición por satjaen; 19/03/2014 a las 15:30