Here’s what it takes to create minimal AJAX in WordPress. First, let’s create a button: Then functions.php include a Javascript file called do_ajax.js. It has the dependencies jquery and wp-util: Also in functions.php, we set up a function to handle the AJAX call, and add the actions: Finally, in our do_ajax.js file: And then in your console you should see “Hello!”. That string is being sent from do_ajax.js to the server, and the server simply sends it back again. That’s it – we have minimal AJAX in WordPress up and running! This post was based on this StackOverflow answer, and … Continue reading Minimal AJAX in WordPress
Copy and paste this URL into your WordPress site to embed
Copy and paste this code into your site to embed