Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Giovanni Dalla Rizza
10,637 Pointsmake a javascript request to server
I want to build a site with three boxes: in each box there is a background image, a title and a text. After I have build the backend server where I could input this information how can I add them into the html?
The risult from the server is something like this (an array): [ { title: "Lorem ipsum", text: "Some text.", imageurl: "http://mysite.com", author: "Giovanni", createDate: "2016-09-06T16:14:39.907Z" }, ] thanks for help!
2 Answers
Jesus Mendoza
23,289 PointsYou can use an Ajax call with vanilla JavaScript or jQuery
Tomas Schlepers
18,039 PointsPeople should correct me when I am wrong. As far as I know you can request data from the server using Ajax calls. These can be made using JavaScript if I recall correct (I do not have experience with this myself). I think I would set it up the following:
- Place the images inside a folder "img" inside your public-folder of the website.
- Store the image URI (relative path to the image on your webhosted storage) inside the database
- Retrieve image-data using Ajax call from within Javascript
- Load the image using the image-URI using some sort of image loader (perhaps readFile?)
This way the database will not be clotted with images (performance). Hope this helps some!