Ir para conteúdo

POWERED BY:

Arquivado

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

leo_SJCampos

[Resolvido] Problema com o IE (AJAX)

Recommended Posts

Olá galera.. tenho um codigo, onde recebo parametros vindo de um forumulario html... através de uma funcao eu recupero esses campos e mando para o php.. acontece... que no IE, não esta funcionando, somente no Firefox, e Chrome.. Alguem poderia olhar o codigo e me dizer se há alguma coisa errada?

Valeu Galera...

 

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;
}


function salvar(id)
{
  m1 = document.getElementById('m1').value;
  b1 = document.getElementById('b1').value;
  faltas = document.getElementById('faltas').value;
  m2 = document.getElementById('m2').value;
  b2 = document.getElementById('b2').value;
  faltas2 = document.getElementById('faltas2').value;
 
  xmlhttp = new ajax();
  xmlhttp.enviar('aluno.php?acao=salvar&id='+ id + '&m1='+ m1 + '&b1=' + b1 + '&faltas='+ faltas + '&m2=' + m2 + '&b2='+ b2 + '&faltas2=' + faltas2, "POST", false); 
alert("Boletim Atualizado");
    
}

Compartilhar este post


Link para o post
Compartilhar em outros sites

meio complicado olhar tudo, e não saber para onde olhar... você já debugou o código ?

qual parte para de funcionar ?

 

o instanciamento está acontecendo corretamente ?

Compartilhar este post


Link para o post
Compartilhar em outros sites

então, ele da erro uma linha após entrar na funcao salvar;;; o debug do IE é muito fraco... nao da pra saber....

 

 

function salvar(id)
{
  m1 = document.getElementById('m1').value;
  b1 = document.getElementById('b1').value;
  faltas = document.getElementById('faltas').value;
  m2 = document.getElementById('m2').value;
  b2 = document.getElementById('b2').value;
  faltas2 = document.getElementById('faltas2').value;
 
  xmlhttp = new ajax();
  xmlhttp.enviar('aluno.php?acao=salvar&id='+ id + '&m1='+ m1 + '&b1=' + b1 + '&faltas='+ faltas + '&m2=' + m2 + '&b2='+ b2 + '&faltas2=' + faltas2, "POST", false); 
alert("Boletim Atualizado");
    
}

Compartilhar este post


Link para o post
Compartilhar em outros sites

vamos aos poucos então..

 

function salvar(id)
{
 var m1 = document.getElementById('m1').value;
 var b1 = document.getElementById('b1').value;
 var faltas = document.getElementById('faltas').value;
 var m2 = document.getElementById('m2').value;
 var b2 = document.getElementById('b2').value;
 var faltas2 = document.getElementById('faltas2').value;
 
 var url = 'aluno.php?acao=salvar&id='+ id + '&m1='+ m1 + '&b1=' + b1 + '&faltas='+ faltas + '&m2=' + m2 + '&b2='+ b2 + '&faltas2=' + faltas2;

 alert( url ); //confira se tá formando a qs certo, depois remove esse alert
  xmlhttp = new ajax();
  xmlhttp.enviar(url, "POST", false); 
  alert("Boletim Atualizado");
    
}
era melhor que esse 'alert', fizesse algum sentido... como esperar que o ajax retorne.. ou realmente indicar que foi atualizado, se houver sucesso e tal..

Compartilhar este post


Link para o post
Compartilhar em outros sites

então, eu fiz o teste, e parece que o erro da no recebimento do form.

 

m1 = document.getElementById('m1').value;

Há alguma outra maneira de recuperar esses dados sem ser dessa forma?

Compartilhar este post


Link para o post
Compartilhar em outros sites

hein?!

 

tá.. mas oque aconteceu 'de errado'?

como voltou o alert da variavel url?

 

você declarou as var como indiquei ??

Compartilhar este post


Link para o post
Compartilhar em outros sites

Sim, mas só retorna quando eu comento a parte de cima, ou seja, a parte onde recupero esses campos do formulario...

ai o alert imprime a url certinho...

Mas o problema esta quando eu tento descomentar aquela parte de cima...

 

da esse erro

 

O objeto não dá suporte para a propriedade ou método

Compartilhar este post


Link para o post
Compartilhar em outros sites

posta o html, ou se possível um link para o site.

Compartilhar este post


Link para o post
Compartilhar em outros sites


<?php

 

session_start();

$_SESSION['id_professor'];

if ($_SESSION['validacao'] == 2)

{

 

?>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<link href="../../sistema/css/css_sys.css" rel="stylesheet" type="text/css" />

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

<script type="text/javascript">

function MM_reloadPage(init) { //reloads the window if Nav4 resized

if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {

document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}

else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();

}

MM_reloadPage(true);

 

function MM_jumpMenu(targ,pag,selObj,restore){ //v3.0

eval(targ+".location.href='"+pag+selObj.options[selObj.selectedIndex].value+"'");

if (restore) selObj.selectedIndex=0;

}

</script>

<script language="javascript" src="crucifer.js"></script>

</head>

 

<body>

<form name="form1" method="post" action="notas.php?disc=<? echo $disc?>">

<table width="223" border="0" align="center" class="tema">

<caption>

<img src="../../sistema/img/icones/report.png" /> Lançamento de Notas

</caption>

<?php

$id_professor = $_SESSION['id_professor'];

include("../con_bd_methodo/conexao_bd.php");

?>

<tr>

<th><div align="left">Discplina:</div></th>

<td><div align="left">

<select name="disc" class="input" id="disc">

<? if ($disc!='')

{?>

<option value="<? echo $disc ?>" selected="selected"><? echo $disc ?></option>

<? }

else

{?>

<option value="" >Selecione</option>

<? }?>

<? $stmt=mysql_query("select * from disciplinas where id_professor = '$id_professor'");

while ($row=mysql_fetch_object($stmt))

{

?>

<option value="<? echo $row->id_disciplinas?>"><? echo $row->nome_oficial?></option>

<? } ?>

</select>

</div></td>

</tr>

<tr>

<td colspan="2"><div align="center">

<input name="botao1" type="submit" class="input" id="botao" value="Enviar">

</div></td>

</tr>

</table>

</form>

<?

if($_POST['botao1']=='Enviar'){

 

?>

<table width="684" border="1" class="tema" align="center" id="tabela">

<tr>

<td width="295">Aluno</td>

<td width="25" nowrap>M1</td>

<td width="25">B1</td>

<td width="45">Faltas</td>

<td width="25">M2</td>

<td width="25">B2</td>

<td width="45">Faltas</td>

<td width="38">Total</td>

<td width="48">Status</td>

<td width="49">Gravar</td>

</tr>

<?php

 

$disc = $_POST['disc'];

 

$stmt=mysql_query("select id_turma from disciplinas where id_disciplinas = '$disc'");

$row = mysql_fetch_object($stmt);

$turma = $row->id_turma;

 

$sel_alunos=mysql_query("select * from alunos where turma = '$turma' order by nome");

while ($row = mysql_fetch_object($sel_alunos)) {

$id = $row->id;

$nome = $row->nome;

?>

<tr>

<td nowrap><div align="left"><? echo $nome;?></div></td>

<td><div align="center">

<input name="m1" type="text" id="m1" size="3" maxlength="3">

</div></td>

<td><div align="center">

<input name="b1" type="text" id="b1" size="3" maxlength="3">

</div></td>

<td><div align="center">

<input name="faltas" type="text" id="faltas" size="3" maxlength="3">

</div></td>

<td><div align="center">

<input name="m2" type="text" id="m2" size="3" maxlength="3">

</div></td>

<td><div align="center">

<input name="b2" type="text" id="b2" size="3" maxlength="3">

</div></td>

<td><div align="center">

<input name="faltas2" type="text" id="faltas2" size="3" maxlength="3">

</div></td>

<td><div align="center">

<input name="total" type="text" id="total" size="3" maxlength="3">

</div></td>

<td><div align="center"></div></td>

<td><a href="javascript:;" onClick="salvar('<?=$id ?>', this.parentNode.parentNode.rowIndex);"><img src="../img/icones/disk.png" border="0"/></a></td>

</tr>

<? } }?>

</table>

</body>

</html>

<?php

}

else

{

echo "<meta http-equiv='refresh' content='0;URL=../index.php' />";

}

?>

Compartilhar este post


Link para o post
Compartilhar em outros sites

provavel que o teu erro, seja por causa desse uso 'não recomendado', da tag <a>

<html>
<head>
<script type="text/javascript">
function salvar( id_aluno )
{
	var m1 = id('m1').value;
	var b1 = id('b1').value;
	var faltas = id('faltas').value;
	var m2 = id('m2').value;
	var b2 = id('b2').value;
	var faltas2 = id('faltas2').value;

	var url = 'aluno.php?acao=salvar&id='+ id_aluno + '&m1='+ m1 + '&b1=' + b1 + '&faltas='+ faltas + '&m2=' + m2 + '&b2='+ b2 + '&faltas2=' + faltas2;
	alert( url );
}
function id( el ){
	return document.getElementById( el );
}
</script>
</head>
<body>
	<input name="m1" type="text" id="m1" size="3" maxlength="3" />
	<input name="b1" type="text" id="b1" size="3" maxlength="3" />
	<input name="faltas" type="text" id="faltas" size="3" maxlength="3" />
	<input name="m2" type="text" id="m2" size="3" maxlength="3" />
	<input name="b2" type="text" id="b2" size="3" maxlength="3" />
	<input name="faltas2" type="text" id="faltas2" size="3" maxlength="3" />
	<input name="total" type="text" id="total" size="3" maxlength="3" />
	<input type="button" value="salvar" onclick="salvar('15')" />
</body>
</html>

troque pelo button, ou chame logo duma vez, no evento onclick da <img />

aqui apareceram erros até no meu FF, ao tentar invocar a função no <a>

Compartilhar este post


Link para o post
Compartilhar em outros sites

William agora funcionou... obrigado....

só mais uma coisa....

porque eu só consigo pegar os valores da primeira linha...

A partir da segunda linha do laço o javascrips nao pega o valor dos campos... você sabe por que?

Valeu

Compartilhar este post


Link para o post
Compartilhar em outros sites

Porque você não deve repetir IDs..

 

 

ID deve ser um identificador unico no documento.

para fazer oque você precisa corretamente, que é: pegar os campos de um formulario, sem saber o nome/id, e nem qntos são, use essa função que postei um tempo atrás:

function form2Qs()
aqui:

http://forum.imasters.com.br/index.php?/topic/393224-fazer-tudo-na-div-idconteudo/

Compartilhar este post


Link para o post
Compartilhar em outros sites

Não entendi. nao estou repetindo os ids.. como que eu posso usar essa sua função para o meu caso?

Preciso pegar os valores dos campos e mandar para o php via ajax

Compartilhar este post


Link para o post
Compartilhar em outros sites

está repetindo sim..

 

aperte Ctrl + U (Exibir > Código Fonte)

 

veja, você tem um laço de repetição:

while ($row = mysql_fetch_object($sel_alunos)) {

e dentro dele você tem os IDs:

while ($row = mysql_fetch_object($sel_alunos)) {
                         $id = $row->id;
                         $nome = $row->nome;
  ?>
  <tr>
    <td nowrap><div align="left"><? echo $nome;?></div></td>
    <td><div align="center">
      <input name="m1" type="text" id="m1" size="3" maxlength="3">
ou seja, cada volta do laço, você cria vários IDs repetidos

 

é 'só usar' cara... a minha função, faz oq você precisa... entenda ela, e tente.

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.