Ver Mensaje Individual
  #15 (permalink)  
Antiguo 24/01/2014, 02:27
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
Respuesta: Convertir código a JQuery

Ok gracias Alexis:

Código Javascript:
Ver original
  1. function valida_envia(e)
  2. {
  3.    
  4.      var telefonos = document.forms['datos'].elements['telefonos'];
  5.     if (telefonos.value.length == 0)
  6.     {
  7.        
  8.         alert("Insertar el nº de teléfono");
  9.  
  10.         telefonos.focus();
  11.  
  12.         return 0;
  13.  
  14.     }
  15.     else
  16.     {
  17.   if (window.event)
  18.     window.event.returnValue=false;
  19.   else
  20.     if (e)
  21.       e.preventDefault();
  22.   enviarFormulario();
  23. }
  24.  
  25. var conexion1;
  26. function enviarFormulario()
  27. {
  28.   conexion1=crearXMLHttpRequest()
  29.   conexion1.onreadystatechange = function(){
  30.      
  31.     var salida = document.getElementById("carga")//El DIV
  32.        
  33.  
  34.     if (conexion1.readyState < 4)
  35.     {
  36.       $('#carga').css({
  37.                 opacity:1,
  38.                 display:'block'
  39.                
  40.             });
  41.          $('#fondo').css({
  42.                 opacity:.25
  43.             });
  44.          
  45.         salida.innerHTML = conexion1.responseText;
  46.        
  47.        
  48.     }else{
  49.    
  50.    
  51.    
  52.         setTimeout(function(){
  53.             var respuesta = conexion1.status == 200 ? conexion1.responseText : conexion1.status == 400 ? "La dirección brindada no existe" : "Error: " + conexion1.status;
  54.            
  55.             salida.innerHTML = respuesta;
  56.            
  57.             //////////////////////////////////////////////////////////////////////////////////////////contenido estado 4
  58.            
  59.               $('#fondo').css({
  60.                 opacity:1
  61.             });
  62.            
  63.            
  64.           $('#carga').css('display','none');
  65.         respuesta.innerHTML = conexion1.responseText;
  66.        
  67.    
  68.        
  69.          var xml = conexion1.responseXML;
  70.             dato=xml.getElementsByTagName("datos");
  71.             if(dato[0].firstChild.nodeValue=="1")
  72.             {
  73.                 num_user=xml.getElementsByTagName("numusuario");
  74.                
  75.                
  76.                 document.getElementById("movil").value =xml.getElementsByTagName("movil")[0].firstChild.nodeValue;
  77.                 document.getElementById("calle").value =xml.getElementsByTagName("calle")[0].firstChild.nodeValue;
  78.                 document.getElementById("dni").value =xml.getElementsByTagName("dni")[0].firstChild.nodeValue;
  79.                 document.getElementById("name").value =xml.getElementsByTagName("name")[0].firstChild.nodeValue;
  80.                 document.getElementById("edificio").value =xml.getElementsByTagName("edificio")[0].firstChild.nodeValue;
  81.                 document.getElementById("numero").value =xml.getElementsByTagName("numero")[0].firstChild.nodeValue;
  82.                 document.getElementById("puerta").value =xml.getElementsByTagName("puerta")[0].firstChild.nodeValue;
  83.                 document.getElementById("piso").value =xml.getElementsByTagName("piso")[0].firstChild.nodeValue;
  84.                 document.getElementById("letra").value =xml.getElementsByTagName("letra")[0].firstChild.nodeValue;
  85.                 document.getElementById("localidad").value =xml.getElementsByTagName("localidad")[0].firstChild.nodeValue;
  86.                 document.getElementById("provincia").value =xml.getElementsByTagName("provincia")[0].firstChild.nodeValue;
  87.                 document.getElementById("email").value =xml.getElementsByTagName("email")[0].firstChild.nodeValue;
  88.                
  89.            
  90.                  
  91.        
  92.             }else(dato[0].firstChild.nodeValue=="0")
  93.                  {                
  94.                      envia();
  95.                      
  96.                          }
  97.        
  98.    
  99.     //////////////////////////////////////////////////////////////////////////////////////////////////////fin contenido estado 4
  100.            
  101.         }, 2000);
  102.        
  103.    };
  104.    
  105.      }
  106.      
  107.   }
  108.   conexion1.open("GET", "val_telef.php?telefonos=" + telefonos.value, false);
  109.   conexion1.send(null);  
  110.  
  111.  
  112.     function crearXMLHttpRequest()
  113. {
  114.   var xmlHttp=null;
  115.   if (window.ActiveXObject)
  116.     xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  117.   else
  118.     if (window.XMLHttpRequest)
  119.       xmlHttp = new XMLHttpRequest();
  120.   return xmlHttp;
  121.    }   
  122. }

Entonces la única diferencia era meter la funcion setTimeout ?
Saludos

Última edición por satjaen; 24/01/2014 a las 02:45