开发者

Looping through facebook ids on the open graph api via json and jquery problem

I have a list of 15 IDs that I am passing into the Facebook Open Graph API. I am having trouble accessing the returned data and showing the data on the page.

CODE

     <script type="text/javascript">
            // The IDs to the fan pages to like

            var likeURLs = ['94517856739', '146175949904'];

            // The base of the URL we will build to query the API 

            var reqURL = "http://graph.facebook.com/?ids=";

            // Construct the rest of reqURL using our fan pages 

            for (var i = 0; i < likeURLs.length; i++) {
                reqURL += likeURLs[i];
                if (i != (likeURLs.length - 1)) { reqURL += ','; } else { reqURL += "&callback=?" } 
            };

            function getLikes() {

                $.getJSON(reqURL, function (data) { alert(data["94517856739"]); alert(data["146175949904"]);
                });
            }

            getLikes();       
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        开发者_StackOverflow社区<div class="likes94517856739">LIKES : alert(data["94517856739"]</div>
        <div class="likes146175949904">LIKES : alert(data["146175949904"]</div>
        </form>
    </body>
    </html>

I've tried a bunch of different ways to get the data and this way works. I am just not able to get the data I want out of the returned data and to the page. Any help would be awesome.


Do you mean something like the following:

<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
    </script>
    <script type="text/javascript">
        // The IDs to the fan pages to like
        var likeURLs = ['94517856739', '146175949904'];

        // The base of the URL we will build to query the API 
        var reqURL = "http://graph.facebook.com/?ids=";

        // Construct the rest of reqURL using our fan pages 
        for (var i = 0; i < likeURLs.length; i++) {
            reqURL += likeURLs[i];
            if (i != (likeURLs.length - 1)) {
                reqURL += ',';
            } else {
                reqURL += "&callback=?"
            }
        };

        function getLikes() {
            $.getJSON(reqURL, function(data) {
                for (var i = 0; i < likeURLs.length; i++) {
                    $('<div/>', {
                        class: "likes" + likeURLs[i],
                        html: "LIKES: " + data[likeURLs[i]].likes
                    }).appendTo('#form1');
                }
            });
        }

        getLikes();
    </script>
</head>

<body>
    <form id="form1" runat="server">
    </form>
</body>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜