Posted By

brianyang on 09/01/09


Tagged

search jquery api using


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

legacye
alexteg


jQuery Search API


 / Published in: jQuery
 

URL: http://code.google.com/apis/ajax/playground/

How to load jQuery and then use the Search API with it.

  1. google.load("jquery", "1");
  2.  
  3. // on page load complete, fire off a jQuery json-p query
  4. // against Google web search
  5. function OnLoad(){
  6. var url = "http://ajax.googleapis.com/ajax/services/search/web?q=google&v=1.0&callback=?";
  7. $.getJSON(url, function (data) {
  8. if (data.responseData.results &&
  9. data.responseData.results.length > 0) {
  10. var results = data.responseData.results;
  11. var content = document.getElementById('content');
  12. content.innerHTML = '';
  13. for (var i=0; i < results.length; i++) {
  14. // Display each result however you wish
  15. content.innerHTML += results[i].titleNoFormatting + "<br/>";
  16. }
  17. }
  18. });
  19. }
  20.  
  21. google.setOnLoadCallback(OnLoad);

Report this snippet  

You need to login to post a comment.