Advertisement
Guest User

Code

a guest
Nov 20th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. // Giphy anzeigen
  2. function validateInput() {
  3. var userInput = document.getElementById('input-text').value;
  4. if (userInput.length > 3) {
  5. alert("Dieser Text ist zu kurz");
  6. } else {
  7. showRandomGiphyWith(userInput);
  8. }
  9. }
  10.  
  11. function showRandomGiphyWith(tag) {
  12. var giphyurl = "https://api.giphy.com/v1/gifs/random?api_key=dc6zaTOxFJmzC&tag=" + tag;
  13.  
  14. request = new XMLHttpRequest;
  15. request.open('GET', giphyurl, true);
  16. request.addEventListener('load', function() {
  17. if (request.status >= 200 && request.status < 400) {
  18. url = JSON.parse(request.responseText).data.image_url;
  19. document.getElementById("output-here").innerHTML = '<center><img src ="'+url+'" title="GIF via Giphy"></center>';
  20. } else {
  21. document.getElementById("output-here").innerHTML = 'reached giphy, but API returned an error';
  22. }
  23. });
  24.  
  25. request.send();
  26. };
  27.  
  28.  
  29. // Giphy entfernen
  30. function clean() {
  31. document.getElementById("output-here").innerHTML = "";
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement