getting facebook share count using javascript

mrs_hardy408

New Member
I wrote the following code: \[code\]function shareCount(url){ var count; $.ajax({ type: "GET", url: "http://api.facebook.com/method/fql.query?query=SELECT+share_count+FROM+link_stat+WHERE+url%3D%22http%3A%2F%2F9gag.com%2Fgag%2F"+encodeURIComponent(url)+"%22", dataType: "xml", success: function(xml) { alert($(xml).find('share_count').text()); return $(xml).find('share_count').text(); } }); //alert(count);}\[/code\]it simply sends a fql query to facebook to get \[code\]share_count\[/code\] for a given link, the link is fine, and \[code\]alert($(xml).find('share_count').text());\[/code\] works but when I return the count the other function says the var is undefined! same thing happens when I uncomment the \[code\]alert()\[/code\] at the end scope.here is part of the other function that sends a request to this function (not sure if its relevant)\[code\]g.innerHTML = h("#template", { id: c.images[a].id, title: c.images[a].title, image: c.images[a].image.small, time: c.images[a].time, votes: c.images[a].votes, url: c.images[a].url, shareCount: shareCount(c.images[a].id) });\[/code\]
 
Back
Top