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!
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
Ceil-Ian MaralitFront End Web Development Techdegree Graduate 19,434 Points
AJAX & Fetch API purposes
Hello everyone! I think I'm a little confused by the purpose of these two.. So, the purpose of these two is just to communicate with a third-party right? In other words, if you don't have anything to get from another website like for example, pictures, you won't need them? Am I right? And in other words, you can't fetch or use XHR on anything that is in your computer, right? And in order to make your page change content without loading is if you have a server-side code with you, that's the time you will need it, right? I think this question sounds stupid because of the obvious meaning of the two. But, I just need some clarifications.
My goal on my website is when the user clicks on one of my navbars, it will look like it did not load at all. Does this have a connection to my question? Please help, I'm just confused. Thank you!
AJAX and API's are different things. I will define each of them and then describe how they can work together.
An API is an application interface. An application interface (API) allows one system to pass data to another system. Say you created a website, and you wanted to display weather data. It would be nice to get the weather data in real time from another source, as opposed to getting your own weather gear. So what you would use would be an API, other companies host these API's and give out access to other people to use their data. How they work is you basically make a request to the API saying, this is the data I would like, and the server responds and says "here you go" and formats it in code in the form of JSON (look this up). So in this example, you may make a request every minute to the API asking for updated weather data (this would make sure your site is up to date).
Now bringing AJAX and the use of an API together. I will continue with my example above with having a weather website. Say you were displaying weather information for the next 7 days. Wouldn't it be nice for the users to not even have to refresh the page when new weather data/information came in. Maybe it was supposed to rain on Tuesday but now the data is saying it will be sunny. Well... bam, AJAX allows the data to come in without even reloading the page and your content is now updated. So, you make the request to the API for new weather data, then using AJAX you populate the data onto the page without even triggering a page refresh to the user!
Hope this was clear. All the best!
Without seeing the video myself, my guess would be that Dave made a query to an API and the API responded to Dave's query with some data in the form of JSON (meaning the API's server responded, this server is not Dave's server).
Now that Dave has the data in the form of JSON, Dave can do whatever he wants with this data. Dave can store it in his own database, or he can just serve the data to the front end of his website and not even have to store it. In either case, if Dave is using the data from the API on his website, Dave can use AJAX to have this data refreshed or updated without causing a page refresh.
I would be extremely careful with storing credit card information on your website. I would recommend using a third party e-commerce provider like Shopify or Paypal to fulfill this service. There is a lot of liability and legal issues that can arise from storing such sensitive data.
If you intend on storing any data relating to your website, you will need to learn back end web development and need to implement a database to your web application.
My favorite web framework is Django, you should check it out I find python very friendly!