How do you make an AJAX call?

Just standardize all your application AJAX calls on this:

APIcall("path/to/api", {parameter :"fred", id : 232}, function(X){ // do something with the result. });

The code the function APIcall function is just over a dozen lines and can be found here together with a longer explanation as to why it works.

Here’s another example of using the function in long hand:

function APPcallback(X){ // call back } var Data = {}; Data.parameter = "fred"; APIcall(Path, Data, APPcallback);

What’s notable is the low cognitive load this puts on the software developer. No having to worry about:

  • Whether this is a GET or a POST

  • What format to put the arguments into.

  • Or how to handle errors.

It’s just JSON in, and JSON out.

Â