【发布时间】:2015-01-16 10:35:18
【问题描述】:
我有一个提取的 twitter 提要(.json 文件),其中包含一些推文,我只想显示它,但由于某种原因我的代码不起作用。谁能帮帮我?
JSFiddle:http://jsfiddle.net/tsokekLw/
代码:
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$.ajax({
url: 'https://dl.dropboxusercontent.com/u/9239655/kevynlebouille.json',
dataType: 'jsonp',
success: function(dataWeGotViaJsonp){
var text = '';
var len = dataWeGotViaJsonp.length;
for(var i=0;i<len;i++){
twitterEntry = dataWeGotViaJsonp[i];
text += '<p><img src = "' + twitterEntry.user.profile_image_url_https +'"/>' + twitterEntry['text'] + '</p>'
}
$('#twitterFeed').html(text);
}
});
})
</script>
</head>
<body>
<div id='twitterFeed'></div>
</body>
</html>
【问题讨论】:
-
我认为
dataType: 'jsonp'是错误的。 -
您需要将其存储在与网站相同的域中,以便您可以提出相关请求。目前你被Same Origin Policy屏蔽了
标签: jquery json twitter timeline