Posted By

nicolaspar on 11/17/11


Tagged

js jquery json cross-domain


Versions (?)

JS data from json - CrossDomian


 / Published in: PHP
 

If not have access to edit json, setting url possible is: url: 'http://graph.facebook.com/4/?callback=getDatosUsuario'

  1. HTML domain1.com
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>JsonCrossDomain</title>
  7. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js" type="text/javascript"></script>
  8. </head>
  9.  
  10. <body>
  11. <div id="container"></div>
  12. <script>
  13.  
  14. $(document).ready(
  15. function(){
  16. jQuery.ajax({
  17. url: 'http://domain2.com/test.json',
  18. dataType: "script",
  19. type: "GET",
  20. cache: false,
  21. callback: null,
  22. data: null
  23. });
  24.  
  25. }
  26. );
  27.  
  28. function getDatosUsuario(datos){
  29. if( confirm('¿Querés ver a quién encontré?') )alert(datos.name);
  30. else alert('jodete!');
  31. }
  32.  
  33. </script>
  34.  
  35. </body>
  36. </html>
  37.  
  38.  
  39. JSON, domain2.com
  40. getDatosUsuario({
  41. "id": "4",
  42. "name": "Mark Zuckerberg",
  43. "first_name": "Mark",
  44. "last_name": "Zuckerberg",
  45. "link": "https://www.facebook.com/zuck",
  46. "username": "zuck",
  47. "gender": "male",
  48. "locale": "en_US"
  49. });

Report this snippet  

You need to login to post a comment.