Showing Google’s response
When you have the search data, you need to show the response from Google,
which will be JavaScript. The response is executed with the JavaScript eval function
|
<title>Google live search</title> |
|
background-color: #FFEEAA; |
|
<script language = “javascript”> |
|
var XMLHttpRequestObject = false; |
|
if (window.XMLHttpRequest) { |
|
XMLHttpRequestObject = new XMLHttpRequest(); |
|
} else if (window.ActiveXObject) { |
|
XMLHttpRequestObject = new ActiveXObject(“Microsoft.XMLHttp”); |
|
function getData(dataSource) |
{
|
if(XMLHttpRequestObject) { |
|
XMLHttpRequestObject.open(“GET”, dataSource); |
|
XMLHttpRequestObject.onreadystatechange = function() |
|
if (XMLHttpRequestObject.readyState == 4 && |
|
XMLHttpRequestObject.status == 200) { |
|
eval(XMLHttpRequestObject.responseText); |
|
XMLHttpRequestObject.send(null); |
|
function getSuggest(keyEvent) |
|
keyEvent = (keyEvent) ? keyEvent: window.event; |
|
input = (keyEvent.target) ? keyEvent.target : |
|
if (keyEvent.type == “keyup”) { |
|
getData(“google.php?qu=” + |
|
var targetDiv = document.getElementById(“targetDiv”); |
|
targetDiv.innerHTML = “<div></div>”; |
|
function sendRPCDone(unusedVariable, searchTerm, arrayTerm, |
|
arrayResults, unusedArray) |
|
if (arrayResults.length != 0) { |
|
for (var loopIndex = 0; loopIndex < arrayResults.length; |
|
“<a href=’http://www.google.com/search?q=” + |
|
arrayTerm[loopIndex] + “‘>” + arrayTerm[loopIndex] + |
|
‘</a></td><td>’ + arrayResults[loopIndex] + “</td></tr>”; |
|
var targetDiv = document.getElementById(“targetDiv”); |
|
targetDiv.innerHTML = data; |
|
<H1>Google live search</H1> |
|
Search for <input id = “textField” type = “text” |
|
name = “textField” onkeyup = “getSuggest(event)”> |
|
<div id = “targetDiv”><div></div></div> |
By cool adch Popularity (698 Views)