Jump to content


Photo

Mais Uma Da Série


  • Faça o login para participar
6 replies to this topic

#1 Henderson

Henderson

    12 Horas

  • Usuários
  • 279 posts
  • Sexo:Não informado
  • Localidade:Santos

Posted 16/02/2008, 00:12

ae galera..
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&aacute; 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&aacute;lido");
	}
}

vlw!

#2 kaduzick

kaduzick

    12 Horas

  • Usuários
  • 229 posts
  • Sexo:Masculino
  • Localidade:Brasília
  • Interesses:Aprender e Ajudar

Posted 27/02/2008, 11:28

Bom dia amigo. O que está acontecendo é o seguinte: você tenta acessar o valor de retorno antes mesmo que o retorno esteja pronto quando você executa o seguinte código:
if (this.processa) {
	return unescape(this.xmlhttp.responseText.replace(/\+/g," "));
}

Para consertar isso você poderia usar a função onreadystatechange do objeto xmlhttp que é chamada a cada mudança de estado do objeto. Você poderia atribuir a essa função a sua função processa que verifica em qual estado o objeto se encontra e qual o status retornado da seguinte forma:
this.xmlhttp.onreadystatechange = this.processa;
Faça isso antes de enviar a requisição ao objeto (antes de executar o send).
O return da função (unescape(this.xmlhttp.responseText.replace(/\+/g," "));) pode ser colocado dentro da função processa como a seguir:
ajax.prototype.processa = function() {
	if (this.readyState == 4 && this.status == 200) {
		alert(this.responseText.replace(/\+/g," "));
	}
}
Espero ter ajudado, qualquer coisa é só voltar aí.
Abraços
kaduzick - The Nerds

#3 LarPhozyHah

LarPhozyHah

    Super Veterano

  • Usuários
  • 14515 posts
  • Sexo:Masculino
  • Localidade:San Miguel de Tucuman

Posted 25/09/2017, 00:00

Buy Kamagra Safely Priligy Auf Rezept Nebenwirkungen Cialis 10mg viagra cialis Antibiotics Buy Amoxil Uk Cheap Comment Les Mecs Last Longer
Kamagra Online Review How To Buy Finasteride Riverside Viagra Sales viagra cialis Viagra Generika De Priligy Product Information Prescription Drugs

#4 LarPhozyHah

LarPhozyHah

    Super Veterano

  • Usuários
  • 14515 posts
  • Sexo:Masculino
  • Localidade:San Miguel de Tucuman

Posted 30/09/2017, 19:14

Macrobid Internet Online Where Can I Buy Betamethasone Priligy Receta Medica cialis buy online Buy Viagra Discrete Uk Discount Card For Effexor Xr
Amoxicillin Dosage In Dogs Priligy Foro Viagra Oder Levitra Forum cialis buy online Drugs No Prescription buy accutane online forum Abilify Online

#5 LarPhozyHah

LarPhozyHah

    Super Veterano

  • Usuários
  • 14515 posts
  • Sexo:Masculino
  • Localidade:San Miguel de Tucuman

Posted 10/10/2017, 14:57

Cialis Online Apotheke Niederlande Viagra Vente Libre En Pharmacie Viagra And Cialis Cheap viagra online pharmacy Amoxicillin Ciprofloxaci Connection Side Effects Of Amoxicillin Clavulin

#6 LarPhozyHah

LarPhozyHah

    Super Veterano

  • Usuários
  • 14515 posts
  • Sexo:Masculino
  • Localidade:San Miguel de Tucuman

Posted 07/11/2017, 14:02

Propecia Funziona Amoxil With Aspirin Buy brand levitra online Ca Based Viagra Supply Propecia Vente En Ligne Posologia Propecia Generico
Amoxicillin 850 Mg Side Effects Vmax Viagra Bien Hora Para Tomar Propecia levitra on line sale Alli Pills For Sale
Besser Als Viagra viagra Contatore Kamagra Holland

#7 HaroNism

HaroNism

    Super Veterano

  • Usuários
  • 15385 posts
  • Sexo:Masculino
  • Localidade:San Miguel de Tucuman

Posted 07/11/2017, 16:45

Buy Cialis England viagra online prescription Cialis In Venlo Kaufen Viagra Levitra Und Cialis
Prix Du Viagra Forum viagra prescription 1 3 Days Shipping On Ed Pills




1 user(s) are reading this topic

0 membro(s), 1 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq