Foros del Web » Programando para Internet » Javascript » Frameworks JS »

Chat AJAX y problemas con IE

Estas en el tema de Chat AJAX y problemas con IE en el foro de Frameworks JS en Foros del Web. Buenas, encontre el siguiente código perteneciente a un tutorial de [URL="http://net.tutsplus.com/tutorials/javascript-ajax/how-to-create-a-simple-web-based-chat-application/"]nettuts[/URL] donde se crea un chat muy básico con un poco de PHP y AJAX. ...
  #1 (permalink)  
Antiguo 30/09/2010, 08:40
Ktulu
Invitado
 
Mensajes: n/a
Puntos:
Chat AJAX y problemas con IE

Buenas, encontre el siguiente código perteneciente a un tutorial de [URL="http://net.tutsplus.com/tutorials/javascript-ajax/how-to-create-a-simple-web-based-chat-application/"]nettuts[/URL] donde se crea un chat muy básico con un poco de PHP y AJAX. Como es de esperar, no es 100% compatible con IE (en cualquiera de sus versiones):
  • En IE8 no funciona el "Enter" para enviar, solo se envía el mensaje si se clickea el boton "Enviar"
  • En IE7 directamente no funciona

Es por ésto que pido ayuda a quienes entienden de AJAX ya que estoy completamente perdido.
Desde ya muchas gracias por la info que puedan darme.

ARCHIVO INDEX.PHP
Código PHP:
<?
    session_start
();

    if(isset(
$_GET['logout'])){

        
//Simple exit message
        
$fp fopen("log.html"'a');
        
fwrite($fp"<div class='msgln' style='color:#F9C28A'><i>El usuario <b>"$_SESSION['name'] ."</b> cerró el chat.</i><br></div>");
        
fclose($fp);

        
session_destroy();
        
header("Location: index.php"); //Redirect the user
    
}

    function 
loginForm(){
        echo
'
        <div id="loginform">
        <form action="index.php" method="post">
            <p>Por favor ingrese su nombre para continuar:</p>
            <label for="name">Nombre:</label>
            <input type="text" name="name" id="name" />
            <input type="submit" name="enter" id="enter" value="Entrar" />
        </form>
        </div>
        '
;
    }

    if(isset(
$_POST['enter'])){
        if(
$_POST['name'] != ""){
            
$_SESSION['name'] = stripslashes(htmlspecialchars($_POST['name']));
        }
        else{
            echo 
'<span class="error">Por favor escriba un nombre</span>';
        }
    }
    
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="/css/estilos.css" />
<link rel="shortcut icon" href="/imagenes/favicon.ico" />
</head>
<body>

    <?php
    
if(!isset($_SESSION['name'])){
        
loginForm();
    }
    else{
    
?>
    <div id="wrapper">
        <div id="menu2">
            <p class="welcome">Bienvenido, <b><?php echo $_SESSION['name']; ?></b> a FM de la Costa</p>
            <p class="logout"><a id="exit" href="#">Salir del Chat</a></p>
            <div style="clear:both"></div>
        </div>
        <div id="chatbox"><?php
        
if(file_exists("log.html") && filesize("log.html") > 0){
            
$handle fopen("log.html""r");
            
$contents fread($handlefilesize("log.html"));
            
fclose($handle);

            echo 
$contents;
        }
        
?></div>

        <form name="message" action="">
            <input name="usermsg" type="text" id="usermsg" size="63" />
            <input name="submitmsg" type="submit"  id="submitmsg" value="Enviar" />
        </form>
    </div>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
    <script type="text/javascript">
    // jQuery Document
    $(document).ready(function(){
        //If user submits the form
        $("#submitmsg").click(function(){
            var clientmsg = $("#usermsg").val();
            $.post("post.php", {text: clientmsg});
            $("#usermsg").attr("value", "");
            return false;
        });

        //Load the file containing the chat log
        function loadLog(){
            var oldscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
            $.ajax({
                url: "log.html",
                cache: false,
                success: function(html){
                    $("#chatbox").html(html); //Insert chat log into the #chatbox div
                    var newscrollHeight = $("#chatbox").attr("scrollHeight") - 20;
                    if(newscrollHeight > oldscrollHeight){
                        $("#chatbox").animate({ scrollTop: newscrollHeight }, 'normal'); //Autoscroll to bottom of div
                    }
                  },
            });
        };
        setInterval (loadLog, 2500);    //Reload file every 2.5 seconds

        //If user wants to end session
        $("#exit").click(function(){
            var exit = confirm("Está seguro que desea salir del Chat?");
            if(exit==true){window.location = 'index.php?logout=true';}
        });
    });
    </script>
    <?php
    
}
    
?>

</body>
</html>
ARCHIVO POST.PHP
Código PHP:
<?
$date
date("i A");

session_start();
if(isset(
$_SESSION['name'])){
    
$text $_POST['text'];

    
$fp fopen("log.html"'a');
    
fwrite($fp"<div class='msgln'>(".$date.") <b>".$_SESSION['name']."</b>: ".stripslashes(htmlspecialchars($text))."<br></div>");
    
fclose($fp);
}
?>
  #2 (permalink)  
Antiguo 30/09/2010, 13:44
Avatar de Ribon  
Fecha de Ingreso: septiembre-2010
Ubicación: El firmamento
Mensajes: 487
Antigüedad: 13 años, 7 meses
Puntos: 91
Respuesta: Chat AJAX y problemas con IE

bueno lo primero es que acá

Código:
$("#submitmsg").click(function(){ 
            var clientmsg = $("#usermsg").val(); 
            $.post("post.php", {text: clientmsg}); 
            $("#usermsg").attr("value", ""); 
            return false; 
        });
le estás diciendo que se envie el mensaje al hacer click sobre el boton, puedes en vez de eso hacer que el evento se dispare al hacerle submit al formulario, eso te permitiría enviar mensajes al darle a ENTER.


IE al detectar un error en javascript detiene la ejecución del script (a diferencia de otros navegadores que ignoran la linea con error y continuan con el resto) busca errores dde javascript.

si encuentro alguno te lo hago saber :P
  #3 (permalink)  
Antiguo 28/02/2011, 16:59
Avatar de alfoner  
Fecha de Ingreso: abril-2009
Mensajes: 146
Antigüedad: 15 años
Puntos: 0
Respuesta: Chat AJAX y problemas con IE

yo tengo el problema con el boton intento que me lo envia al presionar enter y no va...

Etiquetas: ajax, chat, enter, explorer, ie7, ie8, internet, php
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 02:07.