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

He hecho cambios y se me para el alert en Respuesta de php.

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

Gracias.