Ajax no FireFox 2.0.0.11

5 respostas
F

Pessoal!
Tenho um cadastro onde valido o campo Matrícula do Professor. Ocorre que dentro do IDE do Eclipse 3.2 e no IE 6.0 funciona. No FF 2.0 ele não funciona.
Parte do form que trata a Matrícula:

<tr>
	<td align="right" class="txtDestaque">Matrícula:&nbsp;<span class="txtCampoObrigatorio">*</span>&nbsp;</td>
	<td><input name="matricula" class="forms" type="text" size="15" maxlength="15" value="<%=matricula%>" onBlur="validarMatricula()"></td>
</tr>

Script que valida a matrícula:

function validarMatricula(){
	 if(window.ActiveXObject) //IE
	  	req = new ActiveXObject("Microsoft.XMLHTTP");
	 else 
	 	if (window.XMLHttpRequest) // nao IE
		  req = new XMLHttpRequest();	  
	 req.open("GET","professor_action.jsp?matricula="+document.formProfessor.matricula.value+"&acao=validaMatricula"+"&id="+document.formProfessor.id.value,false);  // síncrono
	 req.onreadystatechange = function(){
	 if(req.readyState==4){
	   if(req.status == 200){   
	    if(req.responseText.indexOf("true") != -1) {
    	  alert("Matrícula já utilizada");
    	  document.formProfessor.matricula.value ="";
          document.formProfessor.matricula.focus();
         }
   		}
  	  }
 	 }
	 req.send(null);
}

JSP que é chamado:

if (acao.equals("validaMatricula")) {
	Professor prof = professorDao.getProfessorMatricula(request.getParameter("matricula"));
	if (prof != null && prof.getPfr_id()!= id) {
		out.print("true");
	}
}

Coloquei um Alert no SCRIPT mas ele nem chega a executar.
Grato.

5 Respostas

javaAurelio

ve o que é retornado aqui —> req.status

F

javaAurelo!
Implementei o Alert e ele mostra o primeiro (Estou Aqui) e segundo alert (Estou Aqui 1), o que está após o "req.onreadystatechange = function() " não aparece.

function validarMatricula(){
	alert("estou aqui");
	 if(window.ActiveXObject) //IE
	  	req = new ActiveXObject("Microsoft.XMLHTTP");
	 else 
	 	if (window.XMLHttpRequest) // nao IE
		  req = new XMLHttpRequest();	  
	 req.open("GET","professor_action.jsp?matricula="+document.formProfessor.matricula.value+"&acao=validaMatricula"+"&id="+document.formProfessor.id.value,false);  // síncrono

     alert("estou aqui 1");	 

	 req.onreadystatechange = function(){

 	 alert(req.readyState);

	 if(req.readyState==4){
	 
       alert("estou aqui 2 ");	 
       
	   if(req.status == 200){   
	    if(req.responseText.indexOf("true") != -1) {
    	  alert("Matrícula já utilizada");
    	  document.formProfessor.matricula.value ="";
          document.formProfessor.matricula.focus();
         }
   		}
  	  }
 	 }
	 req.send(null);
}
nbluis

Tem certeza que essa pagina retorna alguma conteudo?
Não retorna um 404 ??

F

No IE e no IDE do Eclipse está funcionando.

F

javaAurelio!
No endereço abaixo é comentado que o Ajax não roda no FF quando é servidor local. Segue o link:

http://gujs.com.br/blog/2007/03/tutorial-basico-sobre-ajax

Se procede, eu não sei. Mas testei aqui e funcionou.
Grato pela atenção.

Criado 12 de dezembro de 2007
Ultima resposta 12 de dez. de 2007
Respostas 5
Participantes 3