I fetch the image URL, then I insert this URL into image' src, but it did not show any image? I followed the idea in here (https://stackoverflow.com/a/12784213/8229192)
Here is my code:
Html:
<h1>Gif image search</h1>
<div id="problemform" class="form-inline">
<input id="probleminput" class="form-inline" placeholder="Enter your keyword" type="text" style="display: inline;"></input>
<button id="problemsubmit" class="btn" style="display: inline-block;">Submit</button>
</div>
<div>Showing <h2 id="resultCount">0</h2>results<div>
<img src="" id="picture"/>
js code:
$('#problemsubmit').on('click', function(event) {
event.preventDefault();
var formInput = $('#probleminput').val();
var xhr = $.get("http://api.giphy.com/v1/gifs/search?q=" + formInput + "&api_key=o1H3Da15oqhgM3WlAhPnQYJV8g9l3NdV&limit=6");
xhr.done(function(data) {
console.log("success got data", data);
$('#resultCount').html(data.data.length);
var imageString = data.data[0].url + "";
$('#picture').attr('src', imageString);
}
);
});