Okay, so I’m an idiot right? Just wanted to get that out of the way before we covered dove into AJAX requests. So when I “break something down for you” you should always take it with a grain of salt.

Ajax is an acronym, and it stands for Asynchronous Javasc — — blah blah blah who cares. You can find that out with two seconds and an internet browser. You came here because you’re stupid and want an explanation suited to you. Right on. What Ajax is, is a bunch of technologies that can do things which normally require a page refresh…. Without a page refresh. WOW. Your sick Facebook status about Trump would usually require you to refresh the page when you click post. Not with AJAX requests though! This scenario describes Asynchronous Javascript. You are taking information from the client side browser and sending it to a server side file.

Word 'Ajax' of the yellow square pixels on a black matrix background

The X in Ajax stands for XML which is a markup language and to be honest I don’t know what the point of it is when there is a JSON alternative. JSON and XML are both ways of transmitting data which are compatible to most languages, however, JSON is much more popular in 2018 than XML. So, they should call Ajax Ajaj. I don’t write the rules though.

So where it is hard for data to be passed from JavaScript to PHP regularly, it would be extremely simple for data to be encoded into JSON from JavaScript and passed to a PHP file where it is decoded and submitted to a database or some other actions are taken.

You can stop reading here if you understand what Ajax is and why you use it because this next section will be technical stuff, and by clicking on this article you admitted you were an idiot… so.

url: ‘dashboard.php’,
type: ‘get’,
data: ‘name=notifications’,
dataType: ‘html’,
success: function(data){
document.getElementById(‘body’).innerHTML = data;

Okay the code above is a very basic AJAX request using JQuery. This code is calling a file ‘dashboard.php’ and saying “OI! Gimme de html m8”. No but really, the ‘data’ field is a $_GET request to the PHP file.

In order to give the Ajax what I want to give it, my PHP file says “if the incoming request is asking for the name=notifications, give them this data. Which just so happens to be any notifications the user may have in this case.

Then in the success field, which is what will happen if the request is completed properly, the parameter “data” is the response data ( I have absolutely no clue why or how this is the case, but it is. It defies everything I know about functions, but if it works, it works.). So I say, if the request is successful, change the element with the ID ‘body’ to equal the response.

That’s all I know about AJAX requests, and now it’s probably all you know about Ajax too. Unless you’re reading this and you know more than me, in which case you should use your time more productively or you’ll end up just like your father.

Thanks for reading, idiot.

Check out my article that breaks down Web Dependencies!