Ver Mensaje Individual
  #12 (permalink)  
Antiguo 17/10/2012, 10:47
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

Otra vez gracias Maycol, lo he puesto bien pero sigue sin llegar al alert de envio de formulario con exito es decir no me manda el formulario y se me queda en alert('Mensaje') cuando meto un teléfono que no existe en la base de datos.

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.       ajax.open("GET", "valida1.php?telefono="+telefono, true);
  52.  
  53.       ajax.onreadystatechange=function() {
  54.  
  55.        if ((ajax.readyState==4) && (ajax.status==200)){
  56.        
  57.      respuesta = ajax.responseText
  58.      
  59.      alert('Mensaje' + respuesta);
  60.  
  61.        }
  62.  
  63.         TelefonoExiste = respuesta
  64.      
  65.       }
  66.  
  67.       ajax.send(null);
  68.  
  69.   }
  70.  
  71.  
  72.  
  73.  
  74.  
  75. function GuardaFormulario() {
  76.  
  77.  
  78.  
  79.     if (document.form1.telefono.value.length==0){
  80.  
  81.       alert("Insertar el Teléfono")
  82.  
  83.       document.form1.telefono.focus()
  84.  
  85.       return 0;
  86.  
  87.      }
  88.  
  89.    else if (TelefonoExiste(document.form1.telefono.value).length==0) {
  90.  
  91.      
  92.  
  93.       document.form1.telefono.focus()
  94.  
  95.       return 0;
  96.  
  97.     }
  98.  
  99.     //el formulario se envia
  100.  
  101.     else
  102.    
  103.        alert("El formulario se envio con exito!")
  104.        document.form1.submit();
  105.   }