I am new to rails. I am trying to fetch a randomly image from an api when users reload the page.
In the html, I have,
<%= image_tag, id: 'login_gif', width: "370" %>
In javascript, I have,
let loginGif = document.getElementById('login_gif')
fetch("https://aws.random.cat/meow")
.then(res => res.json())
.then(pic => { (loginGif.attr("src", pic.file ))})
How do I do this? Thanks for any help in advance.
Aucun commentaire:
Enregistrer un commentaire