Reputation: 1
I will display my latest Tweets on my website. On the tweet_json.php everything is working fine but when I will display them on my website he gives me this error:
ReferenceError: listTweets is not defined
I have no idea, why. Can someone help me please?
My piece of code:
<script type="text/javascript" src="twitter/tweet_json.php?count=3&callback=listTweets"></script>
<script type="text/javascript">
$(document).ready(function(){
var refreshID = setInterval(function(){
$.getJSON('twitter/tweet_json.php?count=3', function(data) {
listTweets(data);
$('.twitterfeed').trigger('create');
});
}, 5000);
});
</script>
I copy/paste my twitter app key correctly.
Thanks alot!
Upvotes: 0
Views: 150
Reputation: 659
Maybe listTweets is defined in your
<script type="text/javascript" src="twitter/tweet_json.php?count=3&callback=listTweets"></script>
Are you sure twitter/tweet_json.php is the right path ? Look at your browser console for 404 and javascript errors.
And I don't see any jQuery libraries loaded before you call $(document).ready()
Is that normal ?
Could we see your twitter/tweet_json.php?count=3&callback=listTweets content ?
-EDIT-
You just have to define your listTweets function
function listTweets(data) {
// You process json results here
}
-EDIT2-
function listTweets(data) {
$.each(data, function(index) {
console.log(data[index])
});
}
Watch results from your browser console. You can access fields with data[index].myfield
Upvotes: 1