我正在按照一个教程来实现社交分享计数按钮,就像这篇文章中的用户一样。我已经为 get_social_counts.php 发送了正确的 http 请求,但它仍然无法正常工作。
按钮加载正确,我可以共享页面,但未显示计数。我使用了与教程中完全相同的 HTML。它也不适用于远程服务器。
这是 JavaScript 函数:
function get_social_counts() {
var thisUrl = window.location.protocol + "//" + window.location.host + window.location.pathname;
$.ajax({
type: "GET",
url: 'http://localhost:1234/site/php/get_social_counts.php?thisurl='+thisUrl,
dataType: "json",
success: function (data){
$('a.post-share.twitter span').html(data.twitter);
$('a.post-share.facebook span').html(data.facebook);
$('a.post-share.gplus span').html(data.gplus);
$('a.post-share.stumble span').html(data.stumble);
}
});
}