2012-12-19 32 views
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>​ 

我用上面的代码,当我在我的网站here添加代码的HTML文件,以获取使用JSON + jquery.but我的facebook帖子.the输出表示Facebook的挡住了我的JSON请求

​ 

sign.此代码或任何问题的问题是什么?

+1

有一个很好的理由,你为什么使用Yahoo API封装FB API调用? Facebook的API在客户端JS中也是完全可访问的... – Matt

+0

我们无法使用直接调用getJSON获得facebook源,因此我们必须使用YQL – sami

+0

其他人都可以管理。 Facebook的API也支持JSONP; https://graph.facebook.com/19292868552?callback=foo – Matt

回答

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> 
+0

jsfiddle工作伙伴http://www.doers.lk/post.html我删除了不需要的标志,但它不会通过 – sami

+0

http://jsfiddle.net/DtNxb/1/也 – sami

+0

http://jsfiddle.net/KubtF/2/ – CharliePrynn

1

你有DOCTYPE声明前,一些空白,尝试删除它。 此外,声明字符集为您的网页:

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" /> 
+0

我加入后,那些它不去上班 – sami