Ajax

The Ajax extension is a more simpler and some times a more appropriate alternative to the native WordPress way of doing it. Some wp administrators block the wp-admin access from the frontend, which has a downside in that the native approach accesses the admin ajax url, but since the admin side is blocked, the script won’t be accessed.

This extension is a good alternative.

Overview

Dependencies

This extension requires the Enqueue extension.

You DO NOT NEED to require the enqueue extension in your composer.json. It will automatically be loaded when you require this ajax extension.

Delegate

This extension acts as a delegate (as in “used by”) for the form and admin extensions. Moreover, it may be a delegate for many others.

How to install

Make sure you have read the extension installation guide first.

To install this extension, place the following inside the “require” block of the composer.json file.

Now run composer install  in your terminal. Thats it!

Usage

Step 1/2 - The server side

First of all, we will need to have access to the ajaxurl variable in the javascript so we know where to send our ajax. The following is the server side code. We will also hook up our javascript (see afterwards) and the ajax callback.

We can choose between line 29 and line 36. The difference would be that, using line 29, we will have access to boots_ajax.url as for the ajax url that we can use in our ajax calls. Alternatively, line 36 also does what line 29 would do, but in addition, it will also allow us to use the helper function $.BootsAjax(). We will see how we will be consuming this helper function once we touch the javascript part below.

Step 2/2 - The client side

This will be our javascript (create a js file and name it ‘ajax.js’):

Khan

A die hard programmer!