AJAX - The Complete Reference

(avery) #1

510 Part III: Advanced Topics


That isn’t the only file we see; others are pulled in as well during the process:

What’s interesting here is Google’s approach of creating a generic loader so they can
pull in new versions of code quite easily, rather than having the user point to some new
filename.
Now client side, you must add some code to enable the Google search but it is pretty
minimal. We load the Google search service, instantiate and add a google.search.
SearchConrol object to the page, define some parameters, and make sure to bind it to a
<div> element in our layout.

<script type="text/javascript">
google.load("search", "1");
window.onload = function () {
var searchControl = new google.search.SearchControl();
var options = new google.search.SearcherOptions();
options.setExpandMode(google.search.SearchControl.EXPAND_MODE_OPEN);
searchControl.addSearcher(new google.search.WebSearch(), options);
searchControl.setResultSetSize(google.search.Search.LARGE_RESULTSET);
searchControl.draw(document.getElementById("searchcontrol"));
};
</script>
</head>
<body>
<h1>Google Search API - Automatic</h1>
<hr />
<div id="searchcontrol">Loading...</div>
</body>
</html>

And now we have an in-page Google-powered search box (http://ajaxref.com/ch10/
googlesearchauto.html). Yet this isn’t Ajax-powered in the strict sense of an XHR. In fact, if
you try the other services Google offers like Maps (http://ajaxref.com/ch10/googlemap
.html) and the RSS feed reader (http://ajaxref.com/ch10/googlerssreader.html), you’ll see
the same thing:
Free download pdf