Guest User

Untitled

a guest
Nov 14th, 2022
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. function loadJSON(path, success, error) {
  2. var xhr = new XMLHttpRequest();
  3. xhr.onreadystatechange = function () {
  4. if (xhr.readyState === 4) {
  5. if (xhr.status === 200) {
  6. success(JSON.parse(xhr.responseText));
  7. }
  8. else {
  9. error(xhr);
  10. }
  11. }
  12. };
  13. xhr.open('GET', path, true);
  14. xhr.send();
  15. }
  16.  
  17. loadJSON("https://dtf.ru/vote/get_likers?id=1445267&type=1&mode=raw", getRandom,'jsonp');
  18.  
  19. function getRandom(data)
  20. {
  21. const values = Object.values(data.data.likers)
  22. const randomValue = values[parseInt(Math.random() * values.length)]
  23. console.log('Победитель:')
  24. console.log(randomValue.user_name)
  25. console.log(randomValue.user_url)
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment