Jump to content


Photo

Código Só Funciona Uma Vez!


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

#1 tempest

tempest

    12 Horas

  • Usuários
  • 131 posts
  • Sexo:Masculino
  • Localidade:Caçador, SC
  • Interesses:Php, Mysql e interatividade!

Posted 09/09/2008, 21:05

Olá pessoal, eu estou tentando aprender ajax,
bom estou tentando enviar dois valores get com este codigo:

var xmlhttp = null;

function ajaxRating(id,votos) {
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			xmlhttp = false;
		}
	}

	if  (!xmlhttp && typeof  XMLHttpRequest != 'undefined' ) {
		try  {
			xmlhttp = new  XMLHttpRequest();
		} catch  (e) {
			xmlhttp = false;
		}
	}

	if (xmlhttp) {
		xmlhttp.onreadystatechange = processadorMudancaEstado;
		xmlhttp.open("GET", "http://www.site.com/recebe_voto.php?id=" + id + "&rating=" + votos ,true);
		xmlhttp.setRequestHeader('Content-Type','text/xml');
		xmlhttp.setRequestHeader('encoding','ISO-8859-1');
		xmlhttp.send(null);
	}
}


Aqui a função para readystatechange:

function processadorMudancaEstado () {
	if ( xmlhttp.readyState == 4) { // Completo
		if ( xmlhttp.status == 200) { // resposta do servidor OK
			document.getElementById("rating").innerHTML =xmlhttp.responseText;
		} else {
			alert( "Problema: " + xmlhttp.statusText );
		}
	}
}
estou enviando assim:

<a href="java script:ajaxRating('2','5');">5</a>


o problema é que no firefox e no ie só funcionou uma vez :unsure:
quando tentei novamente, nada acontece!

o que pod ser?

no chrome funciona normal; :lol:
Posted Image
Css - Flash - Php?...
<? echo "Compartilhar é uma boa forma de aprender"; ?>

#2 Roberto Oliveira

Roberto Oliveira

    Novato no fórum

  • Usuários
  • 1 posts
  • Sexo:Não informado

Posted 11/09/2008, 11:59

Bom, se vc tiver o plugin do firebug no seu firefox, ele apontará onde está o erro, já tentou isso?


se já tentou, diga qual foi o erro que o firebug apontou?



outra coisa, nunca usei a chamada de um javascript da maneira que vc colocou:

<a href="java script:ajaxRating('2','5');">5</a>


ente assim:

<a href="java script:ajaxRating('2','5');">5</a> (sem espaço java script)

ou assim:

<label style="cursor:pointer;" onclick="ajaxRating('2','5');">5</label>

#3 tempest

tempest

    12 Horas

  • Usuários
  • 131 posts
  • Sexo:Masculino
  • Localidade:Caçador, SC
  • Interesses:Php, Mysql e interatividade!

Posted 13/09/2008, 14:50

Olá Roberto, valeu por responder,

ah, esse detalhe estava certo, sem espaço foi erro de digitação minha aqui, hehe!

já resolvi o problema, no console de erros do firefox , ele apontava erro na linha :

xmlhttp.open("GET", "http://www.site.com/recebe_voto.php?id=" + id + "&rating=" + votos ,true);

resolvi o problema, colocando a url somente assim:

xmlhttp.open("GET", "/recebe_voto.php?id=" + id + "&rating=" + votos ,true);

agora está funcionando, tanto no firefox como ieka!

Não sei o porque desse erro, voce sabe?

Abraço; :click:
Posted Image
Css - Flash - Php?...
<? echo "Compartilhar é uma boa forma de aprender"; ?>




0 user(s) are reading this topic

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

IPB Skin By Virteq