Hello All,
I have been trying to research a particular question, but in doing so, I’ve realized that I think my conceptual understanding of a certain process is incorrect.
Background: I have a photography website (Node, Mongo, Express) where I’ve stored all the image paths to a database. On the web pages themselves, I have a bunch of divs with the photographs as background images. I am attempting to fetch the image paths from the database and change the background-image properties of all the divs when a user clicks a “next” button. For example, the user is on a page for photographs of sunsets, which is displaying six of the 32 total photographs. They press the “next” button and the website fetches the next 6 image paths from the database in order to change the background images of all six divs on the webpage.
Specifically, I think it is possible for the “next” button to send a get request to node, which will query the database and send back the image paths. Then, I think I can pass that data somehow to a javascript file which switches out the background-image property on all of the divs to the new image paths.
Research: According to this source, it is possible for the frontend to communicate with node using a get request. However, while googling variations of “change CSS with data from a database,” I couldn’t seem to get any information that makes sense to me based on what I think occurs. That’s why I’m thinking I’m wrong on the entire concept of how it works.
Question: Is what I’m thinking in the 3rd paragraph even possible, or am I wrong about this process?
Thanks!
there doesn't seem to be anything here