How to load jQuery with the Google APIs

By Peter Bromberg

The AJAX Libraries API is a content distribution network and loading architecture for the most popular, open source JavaScript libraries. By using the Google AJAX API Loader's google.load() method, your application has high speed and globally available access to a growing list of the most popular, open source JavaScript libraries. Google works directly with the key stake holders for each library effort and accepts the latest stable versions as they are released.

<html>
<head>
<script src="http://www.google.com/jsapi"></script>
<script>
// Load jQuery
google.load("jquery", "1.4.2");

// on page load complete, fire off a jQuery json-p query
// against Google web search
google.setOnLoadCallback(function() {
$.getJSON("http://ajax.googleapis.com/ajax/services/search/web?q=silverlight&v=1.0&callback=?",
// on search completion, process the results
function (data) {
if (data.responseData.results &&
data.responseData.results.length > 0) {
var results = data.responseData.results;
for (var i=0; i < results.length; i++) {
// Display each result however you wish
document.getElementById('results').innerHTML+= "<a href='"+results[i].url + "'>"+ results[i].titleNoFormatting+"</a><br/>" +results[i].content +"<br/>";
}
}

});
});
</script>
</head>

<body>

<div id="results" />


</body>
</html>

How to load jQuery with the Google APIs  (1241 Views)