Ajax Search as google?

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Feb 2009
Posts: 19
Reputation: Swapsry is an unknown quantity at this point 
Solved Threads: 0
Swapsry Swapsry is offline Offline
Newbie Poster

Ajax Search as google?

 
0
  #1
Feb 27th, 2009
Hi frnds....
i am trying to do search like google....

my files r here......but it displays error.......plz check the code what the error?
error:

error:'window.google.ac' is null or not an object.
char:1.
line:19.


eg: in a text box type "a"
then "a" related words r displayed...

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <?php
  2. $file=fopen("http://www.google.com/complete/search?h1=en&js=true&qu=" . $_GET["qu"],"r");
  3. while(!feof($file)){
  4. $d=fgets($file);
  5. echo $d;
  6. echo "no";
  7. }
  8.  
  9. fclose($file);
  10.  
  11. ?>

google.html
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html xmlns="http://www.w3.org/1999/xhtml">
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>google search</title>
  5. <script language="javascript">
  6. function getData(dataSource)
  7. {
  8. var XMLHttpRequestObject = false;
  9. if(window.XMLHttpRequest){
  10. XMLHttpRequestObject=new XMLHttpRequest();
  11. }else if(window.ActiveXObject){
  12. XMLHttpRequestObject=new ActiveXObject("Microsoft.XMLHTTP");
  13. }
  14. if(XMLHttpRequestObject){
  15. XMLHttpRequestObject.open("GET",dataSource);
  16. XMLHttpRequestObject.onreadystatechange=function(){
  17. if(XMLHttpRequestObject.readyState ==4 && XMLHttpRequestObject.status==200){
  18. eval(XMLHttpRequestObject.responseText);}
  19. }
  20. XMLHttpRequestObject.send(null);
  21. }
  22. }
  23. function connectGoogleSuggest(keyEvent){
  24. var input=document.getElementById("textField");
  25. if(input.value){
  26. getData("google.php?qu=" +input.value);
  27. }else{
  28. var targetDiv=document.getElementById("targetDiv");
  29. targetDiv.innerHTML= "<div></div>";
  30. }
  31.  
  32. }
  33. function sendRPCDone(unusedVariable,searchTerm,arrayTerm,arrayResults,unusedArray){
  34. var data="<table>";
  35. var loopIndex;
  36.  
  37. if(arrayResults.length !=0){
  38. for(var loopIndex=0; loopIndex < arrayResults.length; loopIndex++){
  39. data +="<tr><td>" + "<a href='http://www.google.com/search?q=" + arrayTerm[loopIndex] +"'>" +arrayTerm[loopIndex] +'</a></td><td>' + arrayResults[loopIndex] + "</td></tr>";
  40. }
  41. }
  42. data +="</table>" ;
  43. var targetDiv=document.getElementById("targetDiv");
  44. targetDiv.innerHTML=data;
  45. }
  46. </script>
  47. </head>
  48.  
  49. <body>
  50. <input id="textField" type="text" name="textField" onkeyup="connectGoogleSuggest(event)" />
  51. <div id="targetDiv" ><div></div></div>
  52.  
  53.  
  54. </body>
  55. </html>
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC