我在这里做错了什么想法?
$(document).ready(function(){
var f_page = "ID";
var t_page = "ID";
function add_commas(number) {
if (number.length > 3) {
var mod = number.length % 3;
var output = (mod > 0 ? (number.substring(0,mod)) : '');
for (i=0 ; i < Math.floor(number.length / 3); i++) {
if ((mod == 0) && (i == 0)) {
output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
} else {
output+= ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
}
}
return (output);
} else {
return number;
}
}
// grab from facebook
$.getJSON('https://graph.facebook.com/'+f_page+'?callback=?', function(data) {
var fb_count = data['likes'].toString();
fb_count = add_commas(fb_count);
$('#fb_count').html(fb_count);
});
// grab from twitter
$.getJSON('http://api.twitter.com/1/users/show.json?screen_name='+t_page+'&callback=?', function(data) {
twit_count = data['followers_count'].toString();
twit_count = add_commas(twit_count);
$('#twitter_count').html(twit_count);
});
// grab from website
$.getJSON('json.php?callback=?', function(data) {
web_count = data['count'].toString();
web_count = add_commas(web_count);
$('#website_count').html(web_count);
});
});
但没有在html上显示,但我确实得到了回复{“count”:3}所以也许数据['count']错了? twiiter / facebook的工作,但不是我的计数,就像我在控制台说,我回到阵列
答案 0 :(得分:1)
似乎是由于?回调=?我删除它,它工作正常
答案 1 :(得分:-1)
您必须解析JSON数据
$.getJSON('json.php?callback=?', function(data) {
var responseObj = $.parseJSON(data);
website_count = responseObj.count;
website_count = add_commas(website_count);
$('#website_count').html(website_count);
});