I'm using an API call to Giphy to loop through a string array and return Gifs for each word in the string.
It's working, but the results are showing up out of order.
The beginning of the array is: "STATELY, PLUMP BUCK MULLIGAN CAME FROM THE STAIRHEAD"
And the results show like: Plump Mulligan Came Buck... you get the idea...
Here's the code:
var chapter = "STATELY, PLUMP BUCK MULLIGAN CAME FROM THE STAIRHEAD,"
let words = chapter.split(" ");
for (i=0; i<words.length; i++){
let word = words[i];
var queryURL = "http://api.giphy.com/v1/gifs/search?q=" + word + "&api_key=<MY API KEY>";
$.ajax({
url: queryURL,
method: 'GET'
})
.done(function(response) {
var results = response.data;
var gifDiv = $('<div/>');
var gif = $('<img/>');
gif.addClass('myImg');
gif.attr('src', results[0].images.fixed_height.url);
gif.attr('data-animate', results[0].images.fixed_height.url)
gif.attr('data-state', 'still');
gifDiv.append(gif);
gifDiv.append('<h1>' + word + '</h1>');
gifDiv.appendTo($('#gifs-here'));
})
};
any ideas why the results are out of order?