Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get JSON data and put it into HTML tag

I'm trying to solve a issue regarding to JSON data (getting and post it). Bellow I posted my code which doesn't work and I don't know why? I checked with Firebug and says that it's ok: 200 OK sourceforge.net 1.4 KB 216.34.181.60:80

What I'm trying to do, is to get some stats from a sourceforge project and put it into a div tag.

The link is a valid json (http://sourceforge.net/projects/rdss/files/stats/json?start_date=2010-12-01&end_date=2012-11-24).

<html>
  <head>...</head>
  <body>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script type="text/javascript">
      $(function() {
        $(document).ready(function() {
          $.getJSON("http://sourceforge.net/projects/rdss/files/stats/json?start_date=2010-12-01&end_date=2012-11-24", function(data) {
            $.each(data.posts, function(i,data) {
              var div_data = "<div>"+data.oses+"</div>";
              $(div_data).appendTo("#testjson");
            });
          });
          return false;
        });
      });
    </script>
    <div id="testjson"></div>
  </body>
</html>
like image 600
Apopei Andrei Ionut Avatar asked Jan 16 '26 20:01

Apopei Andrei Ionut


1 Answers

This is a cross domain issue. Check the console. You need write a proxy at the server side to get around. Based on your server side language, you can Google a proxy snippet.

like image 74
geniuscarrier Avatar answered Jan 19 '26 14:01

geniuscarrier



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!