OpenWebSpider

OpenWebSpider Suggest - How does it work?



OpenWebSpider Suggest uses the object XMLHttp to retrieve the most relevant
results for the current query if available in the table of the user-queries
while the user types it in the input box!

The table of the queries is like this:

query  |  results
...    |  ...
xyz    |  10
abcde  |  9
adgj   |  13
...    |  ...

when a user types "a"  OpenWebSpider Suggest ,with the object XMLHttp ,opens a
page that executes a PHP script that gets the queries beginning for "a" from the
table! translating to (my)SQL -> 
"select query, results FROM querylist WHERE query LIKE 'a%' AND results>0 ORDER BY results DESC limit 5"
       |
       V
query  |  results
adgj   |  13
abcde  |  9

Let's see the code:

-------this creates the XMLHttp object------[
    if(window.XMLHttpRequest) 
    {
      try 
      {
        xmlhttp = new XMLHttpRequest();
      } catch(e) 
      {
        xmlhttp = false;
      }
    } 
    else if(window.ActiveXObject) 
    {
      try 
      {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
      } catch(e) 
      {
        try
        {
          xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch(e) 
        {
          xmlhttp = false;
        }
      }
    }
    
]-------------


------this executes the PHP-script-------[
      xmlhttp.open("GET", "script.php?query="+document.form.input_box.value,true);
]-------------


------this variable contains the list of the results-------[
      xmlhttp.responseText;
]-------------


script.php executes the sql-query and generates a list of results!
The main page gets the list and puts it in a <div>

-------------[
          div=document.getElementById("my_hidden_div");
          div.style.display = "";
          div.innerHTML=xmlhttp.responseText;
]-------------


EXAMPLE ( ajax_test-test1.php )

------test1.php-------[
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<script
language=javascript>

var xmlhttp=false;
function test()
{
    if(window.XMLHttpRequest) 
    {
      try 
      {
        xmlhttp = new XMLHttpRequest();
      } catch(e) 
      {
        xmlhttp = false;
      }
    } 
    else if(window.ActiveXObject) 
    {
      try 
      {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
      } catch(e) 
      {
        try
        {
          xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch(e) 
        {
          xmlhttp = false;
        }
      }
    }
    
    if(xmlhttp)
    {
      xmlhttp.open("GET", "test2.php?test="+document.frm.input_box.value,true);
      xmlhttp.onreadystatechange=function()
      {
        if (xmlhttp.readyState==4)
        {
          div=document.getElementById("my_div");
          div.style.display = "";
          div.innerHTML=xmlhttp.responseText;
        }
      }
      xmlhttp.send(null)
    }
}

function displaynone()
{
 div=document.getElementById("my_div");
 div.style.display = "none";
}
</script>
<body> 
<form name="frm" method="get" action="#"> 
  <input autocomplete="off" name="input_box" type="text" value="shen139" onBlur="javascript:displaynone();" onKeyUp="javascript:test();return false;"> 
  <input name="submit" type="submit" value="test"> 
</form> 
<div id="my_div" style="display:none; position:absolute; background-color:#E7E6FF; padding: 0px; border-style:solid; border-width:medium; border-color:#3338FF;"> div </div> 
<p>Shen139 Lab<br> 
  shen139 (at) openwebspider [dot] org<br> 
</p> 
</body>
</html>
]-------------

------test2.php-------[
<?
echo "Test is<br>".$_GET["test"];
?>
]-------------

Shen139 Lab  





Your Text Link here with
Pay-Per-Link


Estate Agents In London
Find an estate agent in London. This section lets you search for estate agents in London, the Home Counties and the UK. You can also read about the estate agent, search their property for sale or rent and contact them via email.

IT Support
Century Computing have been supporting London based clients with IT support solutions for over a decade.

ISO/TS 16949 Courses
Global Automotive Quality System: ISO/TS 16949 courses. This course explains the requirements of the global automotive quality system ISO/TS 16949 and offers guidance as to how these requirements may be satisfied.

Science Sales Jobs
Zenopa Ltd is a recruitment agency that places personnel into the science industry. We specialise in Science Sales Jobs.

Cheap Handbags
These may be cheap handbags, but they are well made and have stunning designs.

Mattresses
The range of mattresses on the Bed Trader website linked above is worth a look before making any purchases. Check it out.

inkjet printer ink
Keep your inkjet printer printing. Get your inkjet printer ink from us to make a great saving and to take advantage of special offers.