How to create an AJAX call in WordPress step by step

WordPress essentially works thanks to PHP language that gets the requests from users and admins, processes these requests and finally constructs the results as HTML pages, ie, PHP sends to you the pages that you see in the browser. Request, process, results; it’s simple. Sometimes however, you need control some elements of the screen after the HTML page has been sent and displayed: a special message on the screen after a checkbox has been checked, the change of an image depending on a select field, etc. and you don’t want to make a new request again. You want that these little elements change on the screen without repeat the whole process of request, process, results… In these cases you need to use the AJAX technique.

The first historical reference to AJAX technique (Roman Villa at Halicarnassus, 4th century AD)

Beyond this more than dubious historical reference of the previous illustration 🙂 , AJAX is a technology of developement supported by javascript and designed precisely for doing these kind of tasks, ie, to comunicate the client site to the server side silently, without a complete requests, just with the execution of a concrete funcion or module on the server side with a few concrete results. Continue reading…