0
 <!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 帖子。但是当我将代码添加到我的站点中的 html 文件时。输出显示

​ 

签名。这段代码有什么问题或任何问题?

4

2 回答 2

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>
于 2012-12-19T12:27:03.557 回答
1

You have some whitespace before the DOCTYPE-declaration, try to remove it. Also, declare a charset for your page:

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" />
于 2012-12-19T12:31:47.807 回答