Posted By

digitalink on 02/21/11


Tagged

ajax callback


Versions (?)

Returning results with ajax


 / Published in: jQuery
 

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

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

Report this snippet  

You need to login to post a comment.