使用 JSON 文件显示 Twitter 提要
Display Twitter feed with a JSON file
我有一个提取的 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',
至此
dataType: 'json',
我有一个提取的 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',
至此
dataType: 'json',