Ajax: For Coders not Cleaners

The Problem

While coding on a project recently I ran into a situation while making an API request. The POST request (being sent from my frontend in REACT) in question was running into a security problem. Since I was sending a request from the client-side, it was violating a CORS preflight check and not allowed. After a bit of digging I realized the endpoint I was trying to hit didn’t allow CORS because at the end of the day, it’s just not secure enough when dealing with certain services. Many SAAS services don’t support CORS so I needed to find a way around it for this one step of the verification process. I knew if I could get the POST fetch working from the RAILS backend I wouldn’t have to deal with CORS at all, thus ensuring I would get the precious access token I would need to make any API calls to the site.

What is Ajax?

AJAX stands for Asynchronous JavaScript And XML and there are a couple key things you need to know about it. AJAX is a way to asynchronously update a web page by exchanging data with a web server. This is important as it allows parts of a page to update without requiring the entire page to reload.

How it Works

In React you must first include jquery to use AJAX. In your project directory install it with:

npm install jquery --save
import $ from "jquery

Tip of the Ajax Iceburg

There are plenty of uses for an AJAX request. To see more you can check out the official docs here.

I love traveling, music, and movies.