在将http迁移到https并还原我们的社交证明后,尝试保留社交份额计数。我正在寻求相关人员的帮助,他们可以就如何总结两个功能并输出DIV中的总股本提供建议:
<div id="pin-div">0</div>
该函数返回HTTP url的计数:
<script type="text/javascript" src="//code.jquery.com/jquery-1.12.4.js"></script>
<script type="text/javascript">
$(function() {
var url = "<?php $page_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; echo $page_url; ?>";
var apiUrl = "https://api.pinterest.com/v1/urls/count.json?callback=receiveCount&url=" + url;
$.ajax({
url: apiUrl,
success: function(result) {
$.each(result, function(key, val) {
console.log(key + " - " + val["receiveCount"]["count"]);
var shareCount = val["receiveCount"]["count"];
$("#pin-div").html(shareCount);
});
}
});
});
</script>
相同的代码返回HTTPS网址的计数:
<script type="text/javascript">
$(function() {
var url = "<?php $page_url = "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; echo $page_url; ?>";
var apiUrl = "https://api.pinterest.com/v1/urls/count.json?callback=receiveCount&url=" + url;
$.ajax({
url: apiUrl,
success: function(result) {
$.each(result, function(key, val) {
console.log(key + " - " + val["receiveCount"]["count"]);
var shareCount = val["receiveCount"]["count"];
$("#pin-div").html(shareCount);
});
}
});
});
</script>
我缺少两个结果的总和吗?
感谢所有JS开发人员,希望这对成千上万的人有所帮助!