facebook阻止了我的json请求

时间:2012-12-19 12:24:23

标签: jquery html facebook json error-handling

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Doers Inc | The one who does something</title>
    <script src="http://code.jquery.com/jquery-1.8.3.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
        $(function () {
            $.ajax({
                url: "http://query.yahooapis.com/v1/public/yql",
                dataType: "jsonp",
                success: function (data) {
                    console.log(data.query.results.json);
                    $.each(data.query.results.json.entries, function (i, v) {
                        $('#entries').append(data.query.results.json.entries[i].content + '<br />');
                     });
                 }, data: {
            q: 'select * from json where url="https://www.facebook.com/feeds/page.php?id=397319800348866&format=json"',
            format: "json"
                    }
           });
       });
   });


</script>
  </head>
  <body>
    <div id="entries"></div>
  </body>
</html>​

我使用上面的代码使用json + jquery来获取我的facebook帖子。但是当我将代码添加到我的网站here中的html文件时。输出显示

​ 

签署。此代码或任何问题的问题是什么?

2 个答案:

答案 0 :(得分:2)

这些角色不是来自facebook,它们在你的代码中。这打破了你的javascript。

修复代码后,它正在运行: http://jsfiddle.net/KubtF/

视图-出处:http://doers.lk/post.html

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Doers Inc | The one who does something</title>

    <script src="http://code.jquery.com/jquery-1.8.3.js"></script>


    <script type="text/javascript">
    $(document).ready(function(){
 $(function () {
    $.ajax({
        url: "http://query.yahooapis.com/v1/public/yql",
        dataType: "jsonp",
        success: function (data) {
            console.log(data.query.results.json);
            $.each(data.query.results.json.entries, function (i, v) {
                $('#entries').append(data.query.results.json.entries[i].content + '<br />');
            });
        }, data: {
            q: 'select * from json where url="https://www.facebook.com/feeds/page.php?id=397319800348866&format=json"',
            format: "json"
        }
    });
});
​
​  });
    </script>


    </head>
    <body>

<div id="entries"></div>​



    </body>
    </html>

答案 1 :(得分:1)

在DOCTYPE声明之前有一些空格,尝试删除它。 另外,为您的页面声明一个charset:

<强> UTF-8:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<强> ISO-8859-1:

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />