0

Im following this tutorial for creating my own Social Share buttons with counters: Social Share Tutorial And I can't figure out why the social share count won't come through.

It's a HubSpot site and the page is here

I've also set up a fiddle to show the code I'm using.

Any insight would be greatly appreciated!

This is the php file being called in the js.

The js:

function get_social_counts() {
var thisUrl = window.location.protocol + "//" + window.location.host +         window.location.pathname;
$.ajax({
    type: "GET",
    url:  'http://cdn2.hubspot.net/hubfs/169677/social_sharing/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);
    }
});
}


$(document).ready(function(){
    get_social_counts();

});

Thanks

juiceman
  • 123
  • 1
  • 9
  • Just as an initial thought, are the 2 whitespaces in your URL intentional? Although whitespaces normally don't matter, they certainly matter when they're contained in a string. I'll look at the rest of what you posted still and let you know if I see anything else. – Fata1Err0r Apr 28 '15 at 13:23

1 Answers1

0

You have a number of problems.

The first is you're requesting a HTTP URL via HTTPS. Your browser's JavaScript console should be showing something like this:

Mixed Content: The page at 'https://fiddle.jshell.net/_display/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://cdn2.hubspot.net/hubfs/169677/social_sharing/get_social_counts.php?thisurl=https://fiddle.jshell.net/_display/'. This request has been blocked; the content must be served over HTTPS.

When corrected, it's still not going to work, because https://cdn2.hubspot.net/hubfs/169677/social_sharing/get_social_counts.php doesn't execute any PHP. Rather than a JSON response, you're getting the raw PHP code back, which JavaScript can't understand.

I don't believe Hubspot will host your PHP code for you.

ceejayoz
  • 176,543
  • 40
  • 303
  • 368
  • ok, I think I understand. So i would want to find a solution that is not dependent on php? I found [link](http://www.jqueryscript.net/social-media/jQuery-Plugin-For-Custom-Social-Share-Buttons-csButtons.html). and made a fiddle: [linl](http://jsfiddle.net/jestlinbaum/3p9r2dfq/). It is supposed to append the count to the button div but it's not. Any thoughts? – juiceman Apr 28 '15 at 15:06
  • ok, I think I understand. So i would want to find a solution that is not dependent on php? I found [this](http://www.jqueryscript.net/social-media/jQuery-Plugin-For-Custom-Social-Share-Buttons-csButtons.html). and made a [fiddle](http://jsfiddle.net/jestlinbaum/3p9r2dfq/). It is supposed to append the count to the button div but it's not. Any thoughts? – juiceman Apr 28 '15 at 15:12
  • @juiceman PHP is fine, but you're apparently trying to host your PHP code on a non-PHP webhost. – ceejayoz Apr 28 '15 at 15:39