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

<html>

<head>

<title>Google live search</title>

<style>

#targetDiv {

background-color: #FFEEAA;

width: 30%;

}

</style>

<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 :

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(unusedVariable, searchTerm, arrayTerm,

arrayResults, unusedArray)

{

var data = “<table>”;

var loopIndex;

if (arrayResults.length != 0) {

for (var loopIndex = 0; loopIndex < arrayResults.length;

loopIndex++) {

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>

</html>


By cool adch   Popularity  (661 Views)