montei uma parada aqui pra poder quando um cara preencher um formulário, verificar se o email que ele preencheu já tá cadastrado no bd..
eu não sei muito de ajax, então eu não sei se o código que to usando tá certo... já usei ele em outros scripts, só copiei e colei.. eu até compreendo o que ele faz, mas não SEI de verdade..
o problema é que no firefox funciona certinho, mas no internet explorer dá esse erro
Os dados necessários para concluir esta operação ainda não estão disponíveis.
aqui o código do ajax
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; }
aqui a função que verifica se o email tá cadastrado
function verificaCadastro(email) { remoto = new ajax(); existe = remoto.enviar("ajax/abrir.php" + "?email=" + email,"GET",""); if (existe) { altClass("email","inputErro"); altImagem("imgEmail","erro"); altMsg("erroEmail","Email já cadastrado"); return true; } else { altClass("email","inputCerto"); altImagem("imgEmail","certo"); altMsg("erroEmail",""); return false; } }
a página abrir.php retorna só true ou false.
alguém sab o que tá errado? qe qe eu faço?
aah.. eu chamo a função assim
<input type="text" name="email" id="email" class="input" maxlength="50" onblur="verificaEmail(this.value);" />
a função verificaEmail é essa
function verificaEmail(email) { cadastro = verificaCadastro(email); if (cadastro) return false; if (email == "") { altClass("email","inputErro"); altImagem("imgEmail","erro"); altMsg("erroEmail","Email em branco"); return false; } var er = new RegExp (/^([0-9a-zA-Z]+([_.-]?[0-9a-zA-Z]*)*@[0-9a-zA-Z]+[0-9,a-z,A-Z,.,-]*(.){1}[a-zA-Z]{2,4})+$/); if (er.test(email)) { altClass("email","inputCerto"); altImagem("imgEmail","certo"); altMsg("erroEmail",""); } else { altClass("email","inputErro"); altImagem("imgEmail","erro"); altMsg("erroEmail","Email inválido"); } }
vlw!