What is Ajax in WordPress?


What is: AJAX
Jackie Woods

AJAX or Asynchronous Javascript and XML, is a group of techniques used in web development which allows a web page to communicate with a server without reloading the page. Using AJAX, applications on the web can exchange data with the server without interfering with the existing web page. Although the “X” is intended to stand for XML, it is not necessary to use XML for the exchange of data. JSON can be used instead.

How To Use AJAX In WordPress
Jeffie Bustamante

This is the WordPress way of including JavaScript files. First, we register the JavaScript file, so that WordPress knows about it (so make sure to create the file and place it somewhere in the plugin). The first argument to the wp_register_script() function is the “handle” of our script, which is a unique identifier. The second is the location of the script. The third argument is an array of dependencies. Our script will require jQuery, so I have added it as a dependency. WordPress has already registered jQuery, so all we needed to add was its handle. For a detailed list of the scripts that WordPress registers, look at the WordPress Codex.

WordPress.org
Jasmin Woodall

Normally, a web page must be refreshed to view new information. For example, when you fill out an online form such as a credit card purchase online, some sites need you to click next to let you know if you filled out something incorrectly. However, with Ajax, not only can the form let you know if you filled out something incorrectly, but it can also let you know if you’ve already made a previous purchase, or if your credit card was expired. Another example of useful Ajax is viewing online maps. Before Ajax, Google Maps required you to click the arrows to navigate their maps, and the page had to reload in order to see the new portion of the map you were interested in. However, Google Maps now utilizes the power of Ajax to fetch the new portions of the map and “redraw” the page where the map moves.

WordPress.org
Emily Alexander

Plugins and themes that insert content via Ajax must trigger the post-load event on document.body after content is inserted. Other scripts that depend on a JavaScript interaction after content insertion, such as AddToAny or a jQuery Masonry script, listen for the post-load event to initialize their required JavaScript. When the post-load event is fired from Jetpack’s Infinite Scroll, for example, AddToAny displays the share buttons for each post, and jQuery Masonry positions elements on the page.

Be the first to comment

Leave a Reply

Your email address will not be published.


*