0

Trying to give a src attribute to a created element. The src should be a url retrieved from the giphy api. I can console.log the response data and everything is fine, however I cannot seem to get the jQuery for creating an element to house the gif correct.

$('.spawn-button').on("click", function(event) { event.preventDefault(); $.ajax({ url: query + $(this).html() + APIKey + limit, method: 'GET' }).done(function(response) { for(var i = 0; i < response.data.length; i++){ // console.log(response.data[i]); // console.log(response.data[i].images.original); $('.gif-container').append("<img src=" + response.data[i].images.fixed_height + ">"); } }); }); 
8
  • 1
    can you show an example of response Commented Sep 12, 2017 at 14:04
  • 2
    Try this $('.gif-container').append("<img src='" + response.data[i].images.fixed_height +"'>"); } Commented Sep 12, 2017 at 14:05
  • that didnt work... i am getting a GET ERR_FILE_NOT_FOUND Commented Sep 12, 2017 at 14:06
  • According to the API docs, fixed_height is an object, so I'm not sure exactly what you're trying to append Commented Sep 12, 2017 at 14:07
  • 2
    Then use response.data[i].images.fixed_height.url Commented Sep 12, 2017 at 14:08

1 Answer 1

1

Can you try with the below code . as per the documentation at https://developers.giphy.com/docs/ fixed_height object has the url property for the GIF image

$('.spawn-button').on("click", function(event) { event.preventDefault(); $.ajax({ url: query + $(this).html() + APIKey + limit, method: 'GET', success: function(response) { for(var i = 0; i < response.data.length; i++){ // console.log(response.data[i]); // console.log(response.data[i].images.original); $('.gif-container').append("<img src=" + response.data[i].images.fixed_height.url + ">"); } }); });

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.