Consider the following script which is used for counting twitter followers. For some reason I get the list twice. I just want the follower count stats for the elements in the array. Any help is greatly appreciated.
echo "<div id='twitter'>
<script type='text/javascript'>
$(document).ready(function(){
var i;
twitterusername = ['Sinbg','followfog','miniclip','vgames'];
for(i=0; i<4; i++){
(function(i){
$.getJSON('http://twitter.com/users/' + twitterusername[i] + '.json?callback=?',
function(data){
$('#twitter').html( document.getElementById('twitter').innerHTML + twitterusername[i] + ' ' +
data.followers_count + ' Followers' + '<br/>');
}
) // end getJSON
})(i);
}// end for??
});</script></div>";
Move the script-tag out of the twitter-div.
Here the example with the script inside.
Here with the script after the div.
I can't reproduce the error with the code you've posted:
You might want to check your php code to see if you are outputting the javascript twice. Another option would be to clear the contents of #twitter before getting the info.