Ir para conteúdo
Fórum Script Brasil
  • 0

Validação De Cadastro Com Ajax, Asp & Access


Marcos-rj

Pergunta

Validação de cadastro: ASP & Access! Banco Access com tabela USUARIOS, campos NOMEUSER e SENHA!

página HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Login</title>
<style>    
<!--
html, body {
    margin:0;
    padding:0;
}    

fieldset {
    width:260px;
    margin:0 auto;
    padding:30px;
}

.texto {
    width:250px;
    border:1px solid gray;
}

.erro {
    width:250px;
    border:1px solid red;
}

.alerta2 {
    border:1px solid gray;
}

.alerta3 {
    border:1px solid gray;
    background-color:gray;
}
-->
</style>
<script src="ajax.js" type="text/javascript"></script>
</head>

<body>
<fieldset>
    <legend>Usuario</legend>
        <form id="form1" name="form1" method="post" action="loginAJAX.asp">
            <div id="alerta"></div>
            <label>Login:</label><br />
            <input name="login" id="login" type="text" maxlength="30" class="texto" onblur="java script:envia('recebeAJAX.asp','POST',false);" /><br />
            <labeL>Senha:</labeL><br />
            <input name="senha" id="senha" type="password" maxlength="30" class="texto" /><br />
          <input name="botao" type="submit" value="Enviar" id="Enviar"/>

    </form>
</fieldset>
</body>
</html>
ajax.js
function ajax() {
};
ajax.prototype.iniciar = function() {

    try{
        this.xmlhttp = new XMLHttpRequest();
    }catch(ee){
        try{
            this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }catch(e){
            try{
                this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }catch(E){
                this.xmlhttp = false;
            }
        }
    }
    return true;
}

ajax.prototype.ocupado = function() {
    estadoAtual = this.xmlhttp.readyState;
    return (estadoAtual && (estadoAtual < 4));
}

ajax.prototype.processa = function() {
    if (this.xmlhttp.readyState == 4 && this.xmlhttp.status == 200) {
        return true;
    }
}

ajax.prototype.enviar = function(url, metodo, modo) {
    if (!this.xmlhttp) {
        this.iniciar();
    }
    if (!this.ocupado()) {
        if(metodo == "GET") {
            this.xmlhttp.open("GET", url, modo);
            this.xmlhttp.send(null);
        } else {        
            this.xmlhttp.open("POST", url, modo);
            this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
            this.xmlhttp.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
            this.xmlhttp.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
            this.xmlhttp.setRequestHeader("Pragma", "no-cache");
            this.xmlhttp.send(url);
        }    

        if (this.processa) {
            return unescape(this.xmlhttp.responseText.replace(/\+/g," "));
        }
    }
    return false;
}

function envia(url, metodo, modo){
    var login = document.getElementById('form1').login.value;
    remoto  = new ajax();
    xmlhttp = remoto.enviar(url + "?login=" + login, metodo, modo);
    if(xmlhttp) {
        document.getElementById('login').className = 'erro';
        document.getElementById('alerta').className = 'alerta2';
        document.getElementById('login').className = 'alerta3';
        document.getElementById("alerta").innerHTML = 'Esse usuário já está cadastrado';
        //alert("Usuario já cadastrado na base de dados!");
        document.getElementById("Enviar").disabled = true;
    } else {
        document.getElementById('login').className = 'texto';
        document.getElementById("Enviar").disabled = false;
        document.getElementById('alerta').className = '';
        document.getElementById("alerta").innerHTML = '';
    }    
}
recebeAJAX.asp
<%
Texto = request("login")

DB = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\intranet\internet\comissao\index\mista\orca\Teste\Teste.mdb"
SQL = "SELECT nomeuser from usuarios WHERE nomeuser= '" & Texto & "'"

Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.CursorLocation = 3
Rs.Open SQL, DB

if Rs.eof <> True then
    response.Write false
End if
%>

No momento do cadastro, ao sair do campo LOGIN, faz-se uma pesquisa na base de dados e retorna se existe ou não já aquele nome cadastrado!

Link para o comentário
Compartilhar em outros sites

5 respostass a esta questão

Posts Recomendados

  • 0
Guest Visitante

Parabéns ...sucinto...simples...breve...objetivo e direto...meus parabéns são pessoas assim que engrandecem os fóruns na net....

Alexandre Garay

:D

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...