Advertisement
RieqyNS13

Untitled

Dec 19th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.33 KB | None | 0 0
  1. <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>
  2. <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>
  3. <div id="result" style="color:green"></div>
  4. <script>
  5. var getJSON = function(url) {
  6.  return new Promise(function(resolve, reject) {
  7.    var xhr = new XMLHttpRequest();
  8.     xhr.open('get', url, true);
  9.     xhr.responseType = 'json';
  10.     xhr.onload = function() {
  11.       var status = xhr.status;
  12.       if (status == 200) {
  13.         resolve(xhr.response);
  14.       } else {
  15.         reject(status);
  16.       }
  17.     };
  18.     xhr.send();
  19.   });
  20. };
  21. var names  = document.getElementsByName("url1");
  22. for(var i=0; i<names.length; i++){
  23.     var decoded = names[i].innerHTML.replace(/&amp;/g, '&');
  24.     getJSON(decoded).then(function(data) {
  25.         document.getElementById("result").innerHTML+= data[0].total_count+"<br>"; //display the result in an HTML element
  26.     }, function(status) { //error detection....
  27.     alert('Something went wrong.');
  28.     });
  29. }
  30.  
  31. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement