Ver Mensaje Individual
  #10 (permalink)  
Antiguo 17/10/2012, 09:11
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: Mensaje de alert para cuando el regisrtro existe en la base de datos

Mayco, perdona pero no me di cuenta de lo de if ((ajax.readyState==4) && (ajax.status==200)), lo he puesto y sigue sin funcionar bien porque me repite tres veces en las alert de Respuesta de php que el telefono existe siempre, estoy metiendo telefonos nuevos que no estan en la base de datos y me tendría que enviar el formulario.Puedes por favor echarle un vistazo?

Código Javascript:
Ver original
  1. //función responsable de crear el objeto para comunicación asíncrona
  2.  
  3. function nuevoAjax() {
  4.  
  5.  
  6.    var xmlhttp=false;
  7.  
  8.    try   {
  9.  
  10.       // Creacion del objeto AJAX para navegadores no IE
  11.  
  12.    
  13.  
  14.       xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
  15.  
  16.    }
  17.  
  18.    catch(e)   {
  19.  
  20.      try  {
  21.  
  22.  
  23.       // Creacion del objet AJAX para IE
  24.  
  25.       xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  26.  
  27.      }
  28.  
  29.      catch(E) {
  30.  
  31.        if (!xmlhttp && typeof XMLHttpRequest!='undefined')
  32.  
  33.         xmlhttp=new XMLHttpRequest();
  34.  
  35.      }
  36.  
  37.  
  38.  
  39.    }
  40.  
  41.    return xmlhttp;
  42.  
  43.   }
  44.  
  45.  
  46.  
  47.  function TelefonoExiste(telefono) {
  48.  
  49.       var ajax=nuevoAjax();
  50.  
  51.       var respuesta = '';
  52.  
  53.  
  54.       ajax.open("GET", "valida1.php?telefono="+telefono, true);
  55.  
  56.       ajax.onreadystatechange=function() {
  57.  
  58.        if ((ajax.readyState==4) && (ajax.status==200))
  59.        
  60.        respuesta = ajax.responseText
  61.        
  62.        alert('El télefono ya existe' + respuesta);
  63.  
  64.         TelefonoExiste = respuesta
  65.  
  66.       }
  67.  
  68.       ajax.send(null);
  69.  
  70.   }
  71.  
  72.  
  73.  
  74.  
  75.  
  76. function GuardaFormulario() {
  77.  
  78.  
  79.  
  80.     if (document.form1.telefono.value.length==0){
  81.  
  82.       alert("Insertar el Teléfono")
  83.  
  84.       document.form1.telefono.focus()
  85.  
  86.       return 0;
  87.  
  88.      }
  89.  
  90.    else if (TelefonoExiste(document.form1.telefono.value).length==0) {
  91.  
  92.      
  93.  
  94.       document.form1.telefono.focus()
  95.  
  96.       return 0;
  97.  
  98.     }
  99.  
  100.     //el formulario se envia
  101.  
  102.     else
  103.    
  104.        alert("El formulario se envio con exito!")
  105.        document.form1.submit();
  106.   }