Ver Mensaje Individual
  #1 (permalink)  
Antiguo 16/04/2006, 23:10
Avatar de B**
B**
 
Fecha de Ingreso: enero-2006
Ubicación: Monterrey,Mexico
Mensajes: 952
Antigüedad: 18 años, 3 meses
Puntos: 3
Busqueda tipo Google Suggestion

Ey.. estoy intentando hacer una busqueda tipo google suggestion.. a traves de un ejemplo que lei.. pero aun no me funcione... este funciona cuando el usuario pone algo en la caja de texto, luego con keyup.. mandara una consulta a googl y a traves de php, recibira los resultados en un arreglo.. pero justo cuando escribo algo y le doy el keyup, sale error de javascript.. creo q el error esta en la funcion q se activa cuando tecleo keyup..pero no encontre algun errror..
el codigo es el siguiente..
Código PHP:
<html>
<
head>
<
title>Google live search</title>
<
style>
#targetDiv {
background-color#FFEEAA;
width30%;
}
</
style>

<
script languaje="javascript">
    var 
Ajax=false;
    if(
window.xmlhttpRequest){
      
Ajax=new XmlhttpRequest();
    }
    else if (
window.ActiveXObject){
      
Ajax=new ActiveXObject("Microsoft.Xmlhttp2");

    }

    function 
getData(datasource){
        if(
Ajax){
          
Ajax.open("GET",datasource);
          
Ajax.onreadystatechange = function(){
            if(
Ajax.readystate == && Ajax.status == 200){
               eval(
Ajax.responsetext);
             }
          }
           
    
Ajax.send(null);
  }
}

    
function 
getSuggest(keyEvent){
  
keyEvent= (keyEvent) ? keyEvent:window.event;
  
input =(keyEvent.target) ? keyEvent.target:keyEvent.srcElement;
    if(
keyEvent.type == "keyup"){
      if(
input.value){
        
getData("google.php?qu=" input.value);

      }
      else{
        var 
targetDiv document.getElementById("targetDiv");
        
targetDiv.innerhtml "<div> </div>";

      }
    }

}

    function 
sendRPCDone(unusedVariablesearchTermarrayTerm,arrayResultsunusedArray)
    {
        var 
data="<table>";
        var 
loopindex;
        if(
arrayResults.length != 0){
          for(var 
loopindexloopindex arrayResults.lengthloopindex++){
            
data+= "<tr> <td>" "<a href='http://www.google.com/search?q=" +
arrayTerm[loopindex] + "'>" arrayTerm[loopindex] +
'</a></td><td>' arrayResults[loopindex] + "</td></tr>";
          }

        }
        
data += "</table>";
        var 
targetDiv =document.getElementbyid('targetDiv');
        
targetDiv.innerhtml data;

  }
</script>
</head>
<body>


<H1>Google live search</H1>
    Search for <input id = "textField" type = "text"
    name = "textField" onkeyup = "getSuggest(event)">

    <div id = "targetDiv"><div></div></div>


</body> 
y el php es el siguiente:

Código PHP:
<?php
        $handle 
fopen("http://www.google.com/complete/search?hl=en&js=true&qu=" .
        
$_GET["qu"], "r");

       while (!
feof($handle)){
            
$text fgets($handle);
            echo 
$text;
        }

       
fclose($handle);
?>
Gracias de antemano