Advertisement
mrghostzoo

test1

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