Posted By

mb2o on 03/31/11


Tagged

JSONP


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

mb2o


JSONP


 / Published in: HTML
 

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

  1. <!--
  2. You are free to copy and use this sample in accordance with the terms of the
  3. Apache license (http://www.apache.org/licenses/LICENSE-2.0.html)
  4. -->
  5.  
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  7. <html xmlns="http://www.w3.org/1999/xhtml">
  8. <head>
  9. <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
  10. <title>Javascript API Samples</title>
  11. </head>
  12. <body style="font-family: Arial;border: 0 none;">
  13. <div id="content"></div>
  14. <script type="text/javascript">
  15. /*
  16. * A technique for avoiding browsers' cross-domain restriction
  17. * Allows you to request information cross-domain from client
  18. * You request a script from a cross domain
  19. * That service must respond in JSON wrapped in a function call you specify
  20. */
  21.  
  22.  
  23. function myFunc() {
  24. if (typeof console != 'undefined') {
  25. console.log(arguments);
  26. } else {
  27. alert('click debug button');
  28. }
  29. }
  30.  
  31.  
  32. var script = document.createElement('script');
  33. script.src = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=Dog&callback=myFunc';
  34. script.type = 'text/javascript';
  35. document.getElementsByTagName('head')[0].appendChild(script);
  36. </script>
  37. </body>
  38. </html>

Report this snippet  

You need to login to post a comment.