Giphy

by Rouvière Valentin

HTML

<h1>Recherche d'images</h1>
<input id="tags">
<button id="bouton">Recherche</button>
<img src="im"/>
<img src="img"/>
<img src="imag"/>

JavaScript

var resultats = document.getElementById('resultats');
var tags = document.getElementById('tags').value;
var xhr = new XMLHttpRequest(); 
var url = 'https://api.giphy.com/v1/gifs/search?q=' + tags + '&api_key=1d5YWGjghqQtzsWwiZhI2SnMeIXkgz1K'
xhr.open('GET', 'url');
xhr.onreadystatechange = function() {
  if (xhr.readyState === 4) {
    var reponse = JSON.parse(xhr.responseText);
    document.getElementById('im').src = 'https://media.giphy.com/media/'+ reponse.data[0].id + '/giphy.gif';
 		document.getElementById('img').src = 'https://media.giphy.com/media/'+ reponse.data[1].id + '/giphy.gif';
  	document.getElementById('imag').src = 'https://media.giphy.com/media/'+ reponse.data[2].id + '/giphy.gif';
      }
xhr.send();
};