APIs and breaking down AJAX

This week I spent a fair amount of time working through using fetch() and get fun API data was an interesting challenge. From an app design perspective, it has opened a new series of data to pull and combine for future and current smaller learning projects that will (hopefully) pan out into some fun interactive apps.

However, as with all new and exciting topics, it included multiple new bugs to work through. One unexpected issue was that my API projects now do not have a real database, so I had to use CORS, a well-built proxy designed for API projects for people like me who are learning (cors-anywhere.herokuapp.com). It now requires you to request permission each day to use it as a temp proxy server. So, for building an app that requires a database to “talk with” for public consumption beyond a learning exercise would require an actual database build… Which is coming soon! Stay tuned for my soon adventures in MySQL.

computer screen with code
Image from JohnsonMartin on Pixabay

Why use something like the load event? What are some disadvantages, alternatives, and when to use them?

A load event runs when the page is fully loaded. By using the “load” event within JavaScript, you can detect when the web page or images, scripts etc. have finished loading. From there, you can run a callback function to act.

One well discussed disadvantage is that load events run instantly, so functions can run before data is retrieved from a database or the backend of the app or website. So, those that those functions may not be able to perform, so in those cases asynchronous functions would be a good choice.

Readystatechange and DOMContenetLoaded are alternatives to the load event. They are initiated when the DOM and its elements are ready to use, but before external resources are fully loaded.

You would use these when you do not need everything to load before running functions.

Here is a great video tutorial:

https://www.youtube.com/watch?v=NdKTdc6dLoc

What is AJAX?

AJAX stands for: Asynchronous JavaScript And XML.

It uses a browser built-in XMLHttpRequest object (to request data from a web server) and it uses JavaScript and HTML DOM to display or use the data.

AJAX apps can use XML to transfer data, but can also transfer data as plain text or JSON text.

AJAX lets web pages to be updated asynchronously by exchanging data with a web server behind the scenes. This makes it possible to update parts of a web page, without reloading the entire web page.

https://www.w3schools.com/whatis/whatis_ajax.asp

What are the advantages and disadvantages of using Ajax?

PROS:

AJAX allows webpages to update serially by exchanging a small amount of data with the server. This way it is possible to update parts of a webpage, without reloading the whole page.

Asynchronous data retrieval can be done by using XmlHttpRequest, so requests are handled effectively and this can improve the performance.

CONS:

AJAX depends on JavaScript. But JavaScript can be implemented differently for different browsers. Browsers which have the JavaScript option disabled will not be able to use its functionality. Therefore, it is not useful or optimal for mobile applications.

The webpage can be hard to debug, and it can increase the code size of your webpage.

Additional resources:

https://way2tutorial.com/ajax/ajax-advantages-and-disadvantages.php

https://dzone.com/articles/pros-and-cons-of-ajax

How does JSONP work? (aka how it is not really Ajax)…

JSONP means JSON with Padding. It requests files using the script tag instead of the XMLHttpRequest object.

Essentially, JSONP loads the JavaScript file and runs the code inside JavaScript file when it is loaded.

Ajax is using XMLHTTPRequest to request any kind of resource, but cross-domain feature depends on browser implement.

Reference Resource for expanded explanations: https://stackoverflow.com/questions/10289789/i-dont-get-how-jsonp-is-any-different-from-ajax

What does it mean when we talk about time complexity of an algorithm?

Time complexity refers to how many actions it takes to iterate through an array to find a specific element or handle and return a solution. If you have to iterate over an array of five items once, then your time complexity would be 1(n). If you have to re-iterate over an array (e.g., bubble sorting), then it would have a higher time complexity.

There are sometimes where a higher time complexity is necessary because other factors may need to be taken into account (e.g., memory)

Additional resources on this topic:

https://www.freecodecamp.org/news/time-complexity-of-algorithms/

antique clock on wooden table
Image by Monoar_CGI_Artist on Pixabay

What are the three laws of algorithm recursion?

1) Must call itself recursively.

2) Must have a base case. Base cases are what let the algorithm stop recursing (so a stopping point otherwise you end up in an infinite loop- not cool!)

3) Must change its state and move towards the base case. The data changes until it meets the conditional of the base case. Essentially, the data is being manipulated in steps or increments towards the final solution.

Reference resources:

https://runestone.academy/runestone/books/published/pythonds/Recursion/TheThreeLawsofRecursion.html

https://sites.google.com/a/lps.k12.co.us/ahs-intro-to-computer-science/home/recursion/2-three-laws-of-recursion

How do I see myself growing as a web developer?

Did my first hello world in December, so growing a lot as far as skills, but also in my mindset that “failure” is actually a learning process, and debugging is not “de-failure” or trying to make up for a shortcoming, it is just part of the process. However, during some debugging periods, especially this weekend while I was sick, it can be difficult to keep a growth mindset at the forefront.

I know that I will be a good developer, because even after hitting some rougher debugging or coding patches, I keep coming back and keep learning. There is a very steep and intimidating learning curve, but being reassured that imposter syndrome is persistent even among senior developers helps, we all have the same struggles, because while I am still at the beginning of my coding journey, everyone has to start with the same “Hello World”.

If anyone needs some quick motivational videos, these are helpful. Also, very easy to listen to in the background when you are busy attempting “real life” when not coding to feel motivated again after some debugging time.

https://www.youtube.com/watch?v=tvuD0W_Dt88

https://www.youtube.com/watch?v=QPXSV0kudyk

I hope this article helps anyone who needed some coding review, is dealing with API call debugging, or is curious about AJAX and what the heck it means (all the cool kids on StackOverflow seem to talk about it plenty)!

Your friend in code,

Rachel

I am an avid adventurer taking readers on my latest journey in learning to code. Let’s get started from 0 experience to programmer!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store