Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

doulo4ever

onreadystatechange com pau

Recommended Posts

Oi pessoal, me dá uma força,

 

Não sei o que é, mas não to conseguindo fazer aparecer o "carregando" do ajax num código aqui.

 

ajax1 = new ajax;function calculoFrete(){				var cepOrigem	 = document.getElementById("cepOrigem").value;				var cepDestino	= document.getElementById("cepDestino").value;	var pesoKg	= document.getElementById("pesoKg").value;	var maoPropria	= document.getElementById("maoPropria").value;	var valorDeclarado	= document.getElementById("valorDeclarado").value;	var avisarRecebimento	= document.getElementById("avisarRecebimento").value;	ajax1.open("POST", "consulta.php", true );	ajax1.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");	ajax1.send("cepOrigem="+cepOrigem+"&cepDestino="+cepDestino+"&pesoKg="+pesoKg+"&maoPropria="+maoPropria+"&valorDeclarado="+valorDeclarado+"&avisarRecebimento="+avisarRecebimento);	ajax1.onreadystatechange = function(){		if (ajax1.readyState == 4){			document.getElementById("resultado").innerHTML = ajax1.responseText;		} else {			document.getElementById("resultado").innerHTML = "Carregando";		}	}}

Era pra aparecer o "carregando" antes do completar o processo, mas ao invéz disso fica tudo branco e quando completa aparecer o resultado e o carregando junto.

 

Onde tá o erro?

 

Na página tá assim:

 

<script>calculoFrete();</script><span id='resultado'></span>

Obrigado,

Paulo.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Eu to com esse mesmo problema aí

Primeiro o mouse trava, se tiver a maozinha fica a maozinha, e for a seta fica a seta... até carregar a requisição completa. Quando o ajax recebe o retorno da página chamada é que o carregando aparece.

 

só que o meu num é questão de posicionamento do DIV não.

Meu HTML tá assim:

<div>		<input type="text" name="txtUserUid" />		<button type="submit" value="adicionar" id="btAdicionar"		 onclick="add_amigo(getElementById('txtUserUid').value, 'btAdicionar', 'msgs_amigos')"		 name="btAdicionar">adicionar</button>	</div>

e o js tá assim:

function add_amigo(uid, id_link, divPraCarregar)	{		modifica_msgs(id_link,"carregando");				//tenta iniciar o AJAX		request = new ajax();				//preenche as partes do html com os dados		document.getElementById(divPraCarregar).innerHTML = request.recebe("processa.php?teste&uid="+uid);				}	}		function modifica_msgs(id_obj, msg)	{		document.getElementById(id_obj).innerHTML = msg;	}

O código do ajax vem de outra página ajax.js. O código completo dele é esse:

function ajax() {};////////////	ESSA FUNÇÃO CARREGA A FUNÇÃO DE AJAX. ELA TESTA VÁRIAS FORMAS DE CRIAÇÃO, UMA PARA CADA TIPO DE NAVEGADOR E CARREGA O AJAX SE UMA DELAS DER CERTO.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;}/////////////	ESSA FUNÇÃO RETORNA O ESTADO ATUAL DA REQUISIÇÃO, SE AINDA TÁ PROCESSANDO, SE ESTÁ PARADO, SE ESTÁ INICIANDO, ETC.ajax.prototype.ocupado = function() {	estadoAtual = this.xmlhttp.readyState;	return (estadoAtual && (estadoAtual < 4));}////////////	ESSA FUNÇÃO RETORNA TRUE SE O AJAX JÁ CONCLUIU O PROCESSAMENTO DA REQUISIÇÃO.ajax.prototype.processa = function() {	if (this.xmlhttp.readyState == 4 && this.xmlhttp.status == 200) {		return true;	}}////////////	ESSA FUNÇÃO RECEBE OS DADOS VINDOS DE UMA PÁGINA HTML, COMO TAGS, FORMS, ETC.ajax.prototype.recebe = function(url) {	if (!this.xmlhttp) {		this.iniciar();	}	if (!this.ocupado()) {			this.xmlhttp.open("GET", url, false);						this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=ISO-8859-1");			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(null);		if (this.processa) {			return unescape(this.xmlhttp.responseText.replace(/\+/g," "));		}	}}////////////	ESSA FUNÇÃO ENVIA OS DADOS PARA O SERVIDOR COMO POST OU GETajax.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=ISO-8859-1");			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;}

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.