Código Ajax funciona solamente con IE8

Bandolera

Lanero Reconocido
6 May 2008
204
Hola chicos malos tengo un código que solamente funciona con IE8, no funciona con FF ni con Chrome:muerto:. Vean las pantallas:

Se muestra un listado de clientes:
ajaxlista1.jpg


Al poner el mouse sobre la lupa de un registro muestra los datos del cliente (solamente en IE8):
ajaxlista2.jpg


Así muestra los datos en Firefox y en Chrome, el listado desaparece y solo queda la ficha::s
ajaxlista3.jpg


Aquí les dejo el código:confused::

AJAX.JS
=====
PHP:
function getXMLHTTPRequest() {
    var req;
    try {
        req = new XMLHttpRequest();
        } catch(err1) {
            try {
            req = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (err2) {
                try {
                req = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (err3) {
                    req = false;
                }
            }
        }
        return req;
}
INDEX.HTML
========
PHP:
<script language="javascript" src="ajax.js"></script>
<script language="javascript">
     http = getXMLHTTPRequest();
 
     function generalista(){
          var myurl = 'cliente_lista.php';
          myRand= parseInt(Math.random()*99999999999999999);
          var modurl = myurl + "?rand=" + myRand;
          http.open("GET", modurl, true);
          http.onreadystatechange = useHTTPResponse;
          http.send(null);
     }
     function useHTTPResponse() {
          if (http.readyState == 4) {
               if(http.status == 200) {
                    var miTexto = http.responseText;
                        document.getElementById('listacliente').innerHTML = (miTexto);
                    }
                    } else {
                    document.getElementById('listacliente').innerHTML='<img src="procesando.gif">';
               }
     }
     function verficha(idcliente){
          var myurl = 'cliente_ficha.php';
          myRand= parseInt(Math.random()*99999999999999999);
          var modurl = myurl + "?idcliente=" + idcliente + "&rand=" + myRand;
          http.open("GET", modurl, true);
          http.onreadystatechange = useHTTPResponse2;
          http.send(null);
     }
     function useHTTPResponse2() {
          if (http.readyState == 4) {
               if(http.status == 200) {
                    var miTexto = http.responseText;
                        document.getElementById('fichadatos').innerHTML = (miTexto);
                    }
          } else {
                    document.getElementById('fichadatos').innerHTML='<img src="procesando.gif">';
               }
     }
</script>
<body onLoad="generalista()">
<table width="500" border="0" cellspacing="0" cellpadding="0">
     <tr>
          <td> <div id="listacliente"></div></td>
          <td> <div id="fichadatos"></div></td>
     </tr>
</table>
</body>
CLIENTE_LISTA.PHP
=============
PHP:
<?php
include("conexion.php");
$sql="SELECT * FROM cliente";
$rs=mysql_query($sql);
$n=mysql_num_rows($rs);
?>
<table width='400' border='0' cellspacing='0' cellpadding='0'>
  <tr>
   <td bgcolor= '#FFFFCC'>NOMBRES</td>
   <td bgcolor= '#FFFFCC'>TELEFONO</td>
  <td></td>
</tr>
<?php
for($k=0;$k<$n;$k++){
$idcliente = mysql_result($rs,$k,"idcliente");
?>
  <tr>
  <td> <?php echo mysql_result($rs,$k,"nombres") ?> </td>
  <td> <?php echo mysql_result($rs,$k,"telefono") ?> </td>
  <td> <a onMOuseOver="verficha(<?php echo $idcliente?>)">Ficha<img src="explorar.jpg"/></a></td>
  </tr>
<?php } ?>
</table>
CLIENTE_FICHA.PHP
=============
PHP:
<?php
include("conexion.php");
 
$idcliente = $_GET["idcliente"];
$sql = "SELECT * FROM cliente WHERE idcliente=$idcliente";
$rs = mysql_query($sql);
$n = mysql_num_rows($rs);
?>
<table width="42%" border="0" bgcolor="#FFFFCC">
  <tr> 
    <td colspan="2"> 
      <div align="center"> 
        <h4><b>FICHA PERSONAL</b></h4>
      </div>
    </td>
  </tr>
  <tr> 
    <td width="22%"><b>Nombres:</b></td>
    <td width="78%"> <?php echo mysql_result($rs,0,"nombres")?></td>
  </tr>
  <tr> 
    <td width="22%"><b>e-mail:</b></td>
    <td width="78%"><?php echo mysql_result($rs,0,"email")?></td>
  </tr>
  <tr> 
    <td width="22%"><b>Direcci&oacute;n:</b></td>
    <td width="78%"><?php echo mysql_result($rs,0,"direccion")?></td>
  </tr>
  <tr> 
    <td width="22%"><b>Telefono:</b></td>
    <td width="78%"><?php echo mysql_result($rs,0,"telefono")?></td>
  </tr>
  <tr> 
    <td width="22%"><b>Fotografia:</b></td>
    <td width="78%"><?php $foto="fotos/".mysql_result($rs,0,"foto")?>
                    <?php echo "<img src='$foto'>"?></td>
  </tr>
</table>
CONEXION.PHP
==========
PHP:
<?php
$cn=mysql_connect("localhost","usuario","clave");
mysql_select_db("clientes");
?>
ESTRUCTURA DE BASE DE DATOS
======================
PHP:
CREATE TABLE IF NOT EXISTS `cliente` (
  `idcliente` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `nombres` varchar(100) NOT NULL,
  `email` varchar(100) NOT NULL,
  `direccion` varchar(100) NOT NULL,
  `telefono` varchar(20) NOT NULL,
  `foto` varchar(20) NOT NULL,
  PRIMARY KEY (`idcliente`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
 
--
-- Volcar la base de datos para la tabla `cliente`
--
 
INSERT INTO `cliente` (`idcliente`, `nombres`, `email`, `direccion`, `telefono`, `foto`) VALUES
(1, 'Cesar Bustamante', 'cabg@librosdigitales.net', 'Av XYZ 123', '654654', 'cesar.jpg'),
(2, 'Juan Perez', 'jperez@yahoo.es', 'Jr abc 7777', '987987', 'jose.jpg'),
(3, 'Rocio Alvarez', 'ralvarez@yahoo.com', 'Calle 111', '3213211', 'rocio.jpg'),
Espero me ayuden a solucionar este problema.
:-p
 
primero empieza por hacer un alert a los catch que tienes en el archivo AJAX.JS

para descartar que el problema sea del navegador... luego seria verificar el codigo html
 
primero empieza por hacer un alert a los catch que tienes en el archivo AJAX.JS

para descartar que el problema sea del navegador... luego seria verificar el codigo html

Yo no domino el tema ajax pero tengo un pequeño còdigo y utilicé el ajax.js de Bandolera con este ejemplo. Este es el codigo de Sumar.html :
PHP:
<html>
<head>
    <title>Prueba Ajax.js</title>
</head>
<script language="javascript" src="ajax.js">
</script>
<script language="javascript">
    http = getXMLHTTPRequest();
    msg = "Procesando";  // Mensaje mientras calcula

    function procesar(){
        var myurl = 'procesar.php';
        var n1 = form1.n1.value;
        var n2 = form1.n2.value;
        var modurl = myurl + "?n1=" + n1 + "&n2=" + n2;
        http.open("GET", modurl, true);
        http.onreadystatechange = useHTTPResponse;
        http.send(null);
    }

    function useHTTPResponse() {
        if (http.readyState == 4) {
            if(http.status == 200) {
                form1.suma.value = http.responseText;
                }
                } else {
                form1.suma.value=msg;
            }
    }

</script>

<body>

    <form name="form1">
          n1: <input type="text" name="n1" /><br/>
          n2: <input type="text" name="n2" /><br/>
          suma: <input type="text" name="suma" disabled="disabled"/><br/>
          <input type="button" value="Calcular" onClick="procesar();"/>
    </form>

</body>

</html>

Y este es el código de procesar.php:
PHP:
<?php
$n1 = $_GET["n1"];
$n2 = $_GET["n2"];
$s = $n1 + $n2;
echo $s;
?>

Lo he probado y funciona en todos los navegadores.
No sé si significa que el .js está bien o no. Pero Funciona.
Suerte.