Ir para conteúdo

Arquivado

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

André Maretti

Problemas de portabilidade no meu script

Recommended Posts

Oi Pessoal...

 

eu aqui de novo com mais um probelma de compatibilidade entre o Internet Explorer e o Firefox no meu script...

 

Meu ajax que funciona maravilhosamente bem no IE... simplesmente não dá sinal de vida no Firefox...

 

nem erro ele dá.. rs

 

será que alguém sabe o que estou fazendo de errado pra ele funcionar no internet explorer e no firefox não!?

 

segue meu script:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>MERCADO DIRETO - Cadastro de Produtor</title>
<style type="text/css">
<!--
.titulo {
	font-family: Calibri, Arial;
	font-size: 24px;
	font-weight: bold;
	color: #634F2C;
	text-align: center;
	vertical-align: middle;
}
.caption {
	font-family: Calibri, Arial;
	font-size: 12px;
	color: #6C1F17;
	text-align: right;
	font-weight: bold;
}
.campos {
	font-family: Calibri, Arial;
	font-size: 11px;
	color: #000;
	border: 1px solid #651C13;
}
.botao {
	font-family: Calibri, Arial;
	font-size: 16px;
	color: #FFF;
	background-color: #651C13;
	border: 2px solid #614B26;
}
.mensagem {
	font-family: Calibri, Arial;
	font-size: 18px;
	font-weight: normal;
	color: #FFF;
	background-color: #651C13;
	text-align: center;
	font-style: italic;
}
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
.somentenum {
	font-family: Calibri, Arial;
	font-size: 10px;
	color: #000;
	border: 1px none #651C13;
}
-->
</style>

<script language="javascript">

function envia(){
	vnomeempresa = document.getElementById('textnomeempresa').value;	
	vnomerepresentante = document.getElementById('textnomerepresentante').value;		
	vendereco = document.getElementById('textendereco').value;	
	vbairro= document.getElementById('textbairro').value;
	vcep= document.getElementById('textcep').value;
	vcidade= document.getElementById('textcidade').value;	
	vestado= document.getElementById('textestado').value;		
	vtelefone= document.getElementById('texttelefone').value;			
	vcelular= document.getElementById('textcelular').value;				
	vcnpj = document.getElementById('textcnpj').value;				
	vie= document.getElementById('textie').value;					
	vrg= document.getElementById('textrg').value;				
	vcpf= document.getElementById('textcpf').value;					
	vemail= document.getElementById('textemail').value;					
	vdatanasc= document.getElementById('textdatanasc').value;					
	vusuario= document.getElementById('textusuario').value;					
	vsenha= document.getElementById('textsenha').value;						
	
	//Inicia o Ajax
	var xmlHttp;
	if(window.ActiveXObject){
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} else if (window.XMLHttpRequest){
		xmlHttp = new XMLHttpRequest();
	}
	
	//Configura o Open do Ajax para chamar o backend
	xmlHttp.open("GET", "cadastro_outros_grava.php?nomeempresa="+vnomeempresa+"&nomerepresentante="+vnomerepresentante+"&endereco="+vendereco+"&bairro="+vbairro+"&cep="+vcep+"&cidade="+vcidade+"&estado="+vestado+"&telefone="+vtelefone+"&celular="+vcelular+"&cnpj="+vcnpj+"&ie="+vie+"&rg="+vrg+"&cpf="+vcpf+"&email="+vemail+"&datanasc="+vdatanasc+"&usuario="+vusuario,+"&senha="+vsenha, true);
	//Configura a função de retorno
	xmlHttp.onreadystatechange = callback;
	//Dispara o Ajax
	xmlHttp.send(null);
	
	//Função de Retorno
	function callback(){
		//Estado 1 é quando ainda está sendo processado
		if(xmlHttp.readyState == 1){
			document.getElementById("mensagem").innerHTML ='Por favor aguarde! Gravando seus dados.';
		}
		//Estado 4 é quando já terminou o processamento
		if(xmlHttp.readyState == 4){
			// Status 200 é página encontrada! Nenhum erro no arquivo de backend do servidor
			if(xmlHttp.status == 200){
					//Pega o resultado em TEXT
					var vresult = xmlHttp.responseText;
					if (vresult == "ERRO") {
						alert("Erro ao gravar seus dados! Tente novamente mais tarde, se o problema persistir entre em contato: andremaretti@gmail.com");
					} else if (vresult == "ERRO_CPF") {						
						document.getElementById("mensagem").innerHTML ='ERRO AO GRAVAR DADOS! O número de CPF informado é inválido.';					
					} else if (vresult == "ERRO_CNPJ") {						
						document.getElementById("mensagem").innerHTML ='ERRO AO GRAVAR DADOS! O número de CNPJ informado é inválido.';											
					} else if (vresult == "OK") {
						document.getElementById("mensagem").innerHTML ='DADOS GRAVADOS COM SUCESSO! Você deve receber em instantes um e-mail com maiores informações.';
						//setTimeout(window.location.href="../index.html", 6000);
					}
			}
		}
	}//FUNCTION CALLBACK
}

function MM_formtCep(e,src,mask) { 
        if(window.event) { _TXT = e.keyCode; }  
        else if(e.which) { _TXT = e.which; } 
        if(_TXT > 47 && _TXT < 58) {  
  var i = src.value.length; var saida = mask.substring(0,1); var texto = mask.substring(i) 
  if (texto.substring(0,1) != saida) { src.value += texto.substring(0,1); }  
     return true; } else { if (_TXT != 8) { return false; }  
  else { return true; } 
        } 
}

/*
*    Script:    Mascaras em Javascript
*     Autor:    Matheus Biagini de Lima Dias
*    Data:    26/08/2008
*    Obs:    
*/
    /*Função  Pai de Mascaras*/
    function Mascara(o,f){
        v_obj=o
        v_fun=f
        setTimeout("execmascara()",1)
    }
    
    /*Função que Executa os objetos*/
    function execmascara(){
        v_obj.value=v_fun(v_obj.value)
    }
    
    /*Função que Determina as expressões regulares dos objetos*/
    function leech(v){
        v=v.replace(/o/gi,"0")
        v=v.replace(/i/gi,"1")
        v=v.replace(/z/gi,"2")
        v=v.replace(/e/gi,"3")
        v=v.replace(/a/gi,"4")
        v=v.replace(/s/gi,"5")
        v=v.replace(/t/gi,"7")
        return v
    }
    
    /*Função que permite apenas numeros*/
    function Integer(v){
        return v.replace(/\D/g,"")
    }
    
    /*Função que padroniza telefone (11) 4184-1241*/
    function Telefone(v){
        v=v.replace(/\D/g,"")                 
        v=v.replace(/^(\d\d)(\d)/g,"($1) $2") 
        v=v.replace(/(\d{4})(\d)/,"$1-$2")    
        return v
    }
    
    /*Função que padroniza telefone (11) 41841241*/
    function TelefoneCall(v){
        v=v.replace(/\D/g,"")                 
        v=v.replace(/^(\d\d)(\d)/g,"($1) $2")    
        return v
    }
    
    /*Função que padroniza CPF*/
    function Cpf(v){
        v=v.replace(/\D/g,"")                    
        v=v.replace(/(\d{3})(\d)/,"$1.$2")       
        v=v.replace(/(\d{3})(\d)/,"$1.$2")       
                                                 
        v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") 
        return v
    }
    
    /*Função que padroniza CEP*/
    function Cep(v){
        v=v.replace(/D/g,"")                
        v=v.replace(/^(\d{5})(\d)/,"$1-$2") 
        return v
    }
    
    /*Função que padroniza CNPJ*/
    function Cnpj(v){
        v=v.replace(/\D/g,"")                   
        v=v.replace(/^(\d{2})(\d)/,"$1.$2")     
        v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") 
        v=v.replace(/\.(\d{3})(\d)/,".$1/$2")           
        v=v.replace(/(\d{4})(\d)/,"$1-$2")              
        return v
    }
    
    /*Função que permite apenas numeros Romanos*/
    function Romanos(v){
        v=v.toUpperCase()             
        v=v.replace(/[^IVXLCDM]/g,"") 
        
        while(v.replace(/^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/,"")!="")
            v=v.replace(/.$/,"")
        return v
    }
    
    /*Função que padroniza o Site*/
    function Site(v){
        v=v.replace(/^http:\/\/?/,"")
        dominio=v
        caminho=""
        if(v.indexOf("/")>-1)
            dominio=v.split("/")[0]
            caminho=v.replace(/[^\/]*/,"")
            dominio=dominio.replace(/[^\w\.\+-:@]/g,"")
            caminho=caminho.replace(/[^\w\d\+-@:\?&=%\(\)\.]/g,"")
            caminho=caminho.replace(/([\?&])=/,"$1")
        if(caminho!="")dominio=dominio.replace(/\.+$/,"")
            v="http://"+dominio+caminho
        return v
    }

    /*Função que padroniza DATA*/
    function Data(v){
        v=v.replace(/\D/g,"") 
        v=v.replace(/(\d{2})(\d)/,"$1/$2") 
        v=v.replace(/(\d{2})(\d)/,"$1/$2") 
        return v
    }
    
    /*Função que padroniza DATA*/
    function Hora(v){
        v=v.replace(/\D/g,"") 
        v=v.replace(/(\d{2})(\d)/,"$1:$2")  
        return v
    }
    
    /*Função que padroniza valor monétario*/
    function Valor(v){
        v=v.replace(/\D/g,"") //Remove tudo o que não é dígito
        v=v.replace(/^([0-9]{3}\.?){3}-[0-9]{2}$/,"$1.$2");
        //v=v.replace(/(\d{3})(\d)/g,"$1,$2")
        v=v.replace(/(\d)(\d{2})$/,"$1.$2") //Coloca ponto antes dos 2 últimos digitos
        return v
    }
    
    /*Função que padroniza Area*/
    function Area(v){
        v=v.replace(/\D/g,"") 
        v=v.replace(/(\d)(\d{2})$/,"$1.$2") 
        return v
        
    }




</script>

</head>

<body scroll="no" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" style="overflow-x:hidden; width:100%; height:100%; overflow-y:hidden;">
<form action="cadastro_produtor_grava.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
  <table width="800" border="0" align="center">
    <tr>
    <td width="450" class="caption"><p>Nome Empresa:</p></td>
    <td width="450"><input name="textnomeempresa" type="text" class="campos" id="textnomeempresa" size="50" maxlength="100" /></td>
  </tr>
  <tr>
    <td class="caption"><p>Nome do Representante:</p></td>
    <td><input name="textnomerepresentante" type="text" class="campos" id="textnomerepresentante" size="50" maxlength="100" /></td>
  </tr>
  <tr>
    <td class="caption">Endereço:</td>
    <td><input name="textendereco" type="text" class="campos" id="textendereco" size="60" maxlength="125" /></td>
  </tr>
  <tr>
    <td class="caption">Bairro:</td>
    <td><input name="textbairro" type="text" class="campos" id="textbairro" size="50" maxlength="10" /></td>
  </tr>
  <tr>
    <td class="caption">CEP:</td>
    <td><input name="textcep" type="text" class="campos" id="textcep" onkeypress="return MM_formtCep(event,this,'#####-###');" size="10" maxlength="9"></td>
  </tr>
  <tr>
    <td class="caption">Cidade</td>
    <td><input name="textcidade" type="text" class="campos" id="textcidade" size="35" maxlength="75" /></td>
  </tr>
  <tr>
    <td class="caption">Estado:</td>
    <td><input name="textestado" type="text" class="campos" id="textestado" size="2" maxlength="2" /></td>
  </tr>
  <tr>
    <td class="caption">Telefone Fixo:</td>
    <td><input name="texttelefone" type="text" class="campos" id="texttelefone" maxlength="14" onKeyDown="Mascara(this,Telefone);" onKeyPress="Mascara(this,Telefone);" onKeyUp="Mascara(this,Telefone);" /></td>
  </tr>
  <tr>
    <td class="caption">Celular:</td>
    <td><input name="textcelular" type="text" class="campos" id="textcelular"  maxlength="14" onKeyDown="Mascara(this,Telefone);" onKeyPress="Mascara(this,Telefone);" onKeyUp="Mascara(this,Telefone);"/></td>
  </tr>
  <tr>
    <td class="caption"><p>CNPJ:</p></td>
    <td><input name="textcnpj" type="text" class="campos" id="textnome6" size="15" maxlength="14" />
      <span class="somentenum">apenas números, sem pontos, traços ou barras</span></td>
  </tr>
  <tr>
    <td class="caption"><p>IE:</p></td>
    <td><input name="textie" type="text" class="campos" id="textnome5" size="15" maxlength="14" /></td>
  </tr>
  <tr>
    <td class="caption">RG do representante:</td>
    <td><input name="textrg" type="text" class="campos" id="textrg" size="15" maxlength="15" /></td>
  </tr>
  <tr>
    <td class="caption">CPF do representante:</td>
    <td><input name="textcpf" type="text" class="campos" id="textcpf" size="14" maxlength="14" />
      <span class="somentenum">apenas números, sem pontos, traços ou barras</span></td>
  </tr>
  <tr>
    <td class="caption">E-Mail:</td>
    <td><input name="textemail" type="text" class="campos" id="textemail" size="70" maxlength="255" /></td>
  </tr>
  <tr>
    <td class="caption">Data de Nascimento:</td>
    <td><input name="textdatanasc" type="text" class="campos" id="textdatanasc" maxlength="10" onKeyDown="Mascara(this,Data);" onKeyPress="Mascara(this,Data);" onKeyUp="Mascara(this,Data);" /></td>
  </tr>
  <tr>
    <td class="caption">Defina seu nome de usuário:</td>
    <td><input name="textusuario" type="text" class="campos" id="textusuario" maxlength="25" /></td>
  </tr>
  <tr>
    <td class="caption">Defina sua senha:</td>
    <td><label>
      <input name="textsenha" type="password" id="textsenha" maxlength="12" />
    </label></td>
  </tr>
  <tr>
    <td colspan="2"> </td>
  </tr>
  <tr>
    <td colspan="2"><div class="mensagem" id="mensagem"> </div></td>
    </tr>
  <tr>
    <td colspan="2" align="center"> </td>
  </tr>
  <tr>
    <td colspan="2" align="center"><label>
      <input name="button" type="button" class="botao" id="button" value="Confirmar Cadastro!" onclick="envia()" />
    </label></td>
    </tr>
  <tr>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td colspan="2"></td>
    </tr>
</table>

</form>
<p> </p>
</body>
</html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Olhe o teu instanciamento do objeto AJAX..

var xmlHttp;
        if(window.ActiveXObject){
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        } else if (window.XMLHttpRequest){
                xmlHttp = new XMLHttpRequest();
        }
não está levando em conta os navegadores standards.

Assim seria melhor: (não testei com resto do teu script)

try {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e) {
        try {
                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(ex) {
                try {
                        xmlHttp = new XMLHttpRequest();
                }
                catch(exc) {
                        alert("Esse browser não tem recursos para uso do Ajax");
                        xmlHttp = null;
                }
        }
}

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.