Ir al contenido


Foto

eliminar mje de registro al iniciar la página con php y ajax video 21


  • Por favor identifícate para responder
No hay respuestas en este tema

#1 calidoskopio

calidoskopio

    Newbie

  • Miembros
  • Pip
  • 6 mensajes

Escrito 16 enero 2012 - 05:48

Estaba viendo el video 21 de php estructurado donde se trabaja con Ajax y quería saber como hacer para que el mje de "Ud. se ha registrado exitosamente" no aperzaca cuando se inicia o recarga la página, sin tener que usar Jquery, supongo que será con JS mediante un evento con ajax usando GetElemntById y que no aparezca , solamente cuando se ha registrado con éxito y hayaredireccionado al index
//index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Comprobar disponibilidad de usario</title>
<script type="text/javascript" src="js/funciones.js"></script>
</head>

<body onload="limpiar();">
<?php
if($_GET["m"]=1){
$msj="Ud. se ha registrado exitosamente";
echo "<h2 style='color:#ff0000'>$msj</h2>";
}else{ echo "";
}
?>
<h2>Ingrese sus datos</h2>

<form action="procesa.php" name="form" method="post">
Nombre:<input type="text" name="nom" />
<div id="div_nom"></div>
<br />
E-Mail:<input type="email" name="correo" />
<div id="div_correo"></div>
</br>
Loging:<input type="text" name="user" onblur="from(document.form.user.value,'div_user','verifica.php');" />
<div id="div_user"></div>
<br />
Paswoord:<input type="password" name="pass" />
<div id="div_pass"></div>
<br />
Confirmar paswoord:<input type="password" name="pass_2" />
<div id="div_pass_2"></div>
<br />
<input id="boton" type="button" value="Ingresar" title="Ingresar" onclick="valida_registro();" />
<input id="boton_2" type="button" value="No se puede ingresar" title="No se puede ingresar" style="display:none"/>
</form>

</body>
</html>

//funciones.js

// Desarrollado por [url=http://www.cesarcancino.com]www.cesarcancino.com[/url]
function getXMLHTTPRequest()
{
var req = false;
try
  {
    req = new XMLHttpRequest(); /* p.e. Firefox */
  }
catch(err1)
  {
  try
    {
    req = new ActiveXObject("Msxml2.XMLHTTP");
  /* algunas versiones IE */
    }
  catch(err2)
    {
    try
      {
      req = new ActiveXObject("Microsoft.XMLHTTP");
  /* algunas versiones IE */
      }
      catch(err3)
        {
        req = false;
        }
    }
  }
return req;
}
var miPeticion = getXMLHTTPRequest();
//*********************************************************************
function from(id,ide,url){
//alert(id);

var mi_aleatorio=parseInt(Math.random()*99999999);//para que no guarde la página en el caché...
var vinculo=url "?id=" id "&rand=" mi_aleatorio;
//alert(vinculo);
miPeticion.open("GET",vinculo,true);//ponemos true para que la petición sea asincrónica
miPeticion.onreadystatechange=miPeticion.onreadystatechange=function(){
              if (miPeticion.readyState==4)
              {
                      if (miPeticion.status==200)
                      {
                              var http=miPeticion.responseText;
  if (http=="si")
  {
document.getElementById(ide).innerHTML="<font color='red'>El usuario " id " no est&aacute; disponible</font>"; 
document.getElementById("boton").style.display="none";
document.getElementById("boton_2").style.display="block";
}else
{
document.getElementById(ide).innerHTML="<font color='green'>El usuario " id " si se encuentra disponible</font>";
document.getElementById("boton").style.display="block";
document.getElementById("boton_2").style.display="none";
}
 
 
                      }
  }else{
  //document.getElementById('resultados').style.display="block";
  document.getElementById(ide).innerHTML="<img src='ima/loading.gif' title='cargando...' />";
              }
      }
      miPeticion.send(null);

}
//******************************************************************
function limpiar()
{
document.form.reset();
document.form.nom.focus();
}
//*****************************************************************************
//Valida correo
function valida_correo(correo) {
  if (/^\w ([\.-]?\w )*@\w ([\.-]?\w )*(\.\w{2,3}) $/.test(correo)){

  return (true)
  } else {
 
  return (false);
  }
}
//******************************************************************
function valida_registro()
{
var form=document.form;
if (form.nom.value==0)
{
document.getElementById("div_nom").innerHTML="<font color='#ff0000'>Ingrese su nombre</font>";
form.nom.value="";
form.nom.focus();
return false;
}else
{
document.getElementById("div_nom").innerHTML="";
}
if (form.correo.value==0)
{
document.getElementById("div_correo").innerHTML="<font color='#ff0000'>Ingrese su E-Mail</font>";
form.correo.value="";
form.correo.focus();
return false;
}else
{
document.getElementById("div_correo").innerHTML="";
}
if (valida_correo(form.correo.value)==false)
{
document.getElementById("div_correo").innerHTML="<font color='#ff0000'>Ingrese un E-Mail v&aacute;lido</font>";
form.correo.value="";
form.correo.focus();
return false;
}else
{
document.getElementById("div_correo").innerHTML="";
}
if (form.user.value==0)
{
document.getElementById("div_user").innerHTML="<font color='#ff0000'>Ingrese un Login</font>";
form.user.value="";
form.user.focus();
return false;
}else
{
document.getElementById("div_user").innerHTML="";
}
if (form.pass.value==0)
{
document.getElementById("div_pass").innerHTML="<font color='#ff0000'>Ingrese su Password</font>";
form.pass.value="";
form.pass.focus();
return false;
}else
{
document.getElementById("div_pass").innerHTML="";
}
if (form.pass_2.value==0)
{
document.getElementById("div_pass_2").innerHTML="<font color='#ff0000'>Confirme su Password</font>";
form.pass_2.value="";
form.pass_2.focus();
return false;
}else
{
document.getElementById("div_pass_2").innerHTML="";
}
if (form.pass.value != form.pass_2.value)
{
document.getElementById("div_pass").innerHTML="<font color='#ff0000'>Los Password ingresados no coinciden</font>";
form.pass.value="";
form.pass_2.value="";
form.pass.focus();
return false;
}else
{
document.getElementById("div_pass").innerHTML="";
}
form.submit();
}

//procesa.php
<?php
//print_r($_POST);
require_once("conexion/conexion.php");
$sql="insert into usuarios values (null,'".$_POST["nom"]."','".$_POST["correo"]."','".$_POST["user"]."','".$_POST["pass"]."')";
//echo $sql;
$res=mysql_query($sql,$con);
header("Location: index.php?m=1");
?>

//verifica.php

<?php
require_once("conexion/conexion.php");
sleep(2);
$sql="select user from usuarios where user='".$_GET["id"]."'";
$res=mysql_query($sql,$con);
if(mysql_num_rows($res)==0)
{
echo "no";
}else
{
echo "si";
}
?>

  • 0




IP.Board spam blocked by CleanTalk.