<p name="url1" style="display:none;">http://api.facebook.com/method/fql.query?query=select%20total_count,like_count,comment_count,share_count,click_count%20from%20link_stat%20where%20url=%27http://www.livingsocial.com/deals/278194-sunset-kayaking-hot-chowder%27&format=json</p>
<p name="url1" style="display:none;">http://api.facebook.com/method/fql.query?query=select%20total_count,like_count,comment_count,share_count,click_count%20from%20link_stat%20where%20url=%27http://www.google.com%27&format=json</p>
<div id="result" style="color:green"></div>
<script>
var getJSON = function(url) {
return new Promise(function(resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open('get', url, true);
xhr.responseType = 'json';
xhr.onload = function() {
var status = xhr.status;
if (status == 200) {
resolve(xhr.response);
} else {
reject(status);
}
};
xhr.send();
});
};
var names = document.getElementsByName("url1");
for(var i=0; i<names.length; i++){
var decoded = names[i].innerHTML.replace(/&/g, '&');
getJSON(decoded).then(function(data) {
document.getElementById("result").innerHTML+= data[0].total_count+"<br>"; //display the result in an HTML element
}, function(status) { //error detection....
alert('Something went wrong.');
});
}
</script>
Comments