mrghostzoo

test

Dec 18th, 2015
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. <p id="url1" style="display:none;">https://api.facebook.com/method/fql.query?query=select%20total_count,like_count,comment_count,share_count,click_count%20from%20link_stat%20where%20url=%27http://google.com%27&format=json</p>
  2. <div id="result" style="color:green"></div>
  3. <script>
  4. var getJSON = function(url) {
  5. return new Promise(function(resolve, reject) {
  6. var xhr = new XMLHttpRequest();
  7. xhr.open('get', url, true);
  8. xhr.responseType = 'json';
  9. xhr.onload = function() {
  10. var status = xhr.status;
  11. if (status == 200) {
  12. resolve(xhr.response);
  13. } else {
  14. reject(status);
  15. }
  16. };
  17. xhr.send();
  18. });
  19. };
  20.  
  21. var test = document.getElementById('url1').innerHTML;
  22. getJSON(test).then(function(data) {
  23. document.getElementById("result").innerHTML = data[0].total_count; //display the result in an HTML element
  24. }, function(status) { //error detection....
  25. alert('Something went wrong.');
  26. });
  27. </script>
Advertisement
Add Comment
Please, Sign In to add comment