Why is admin ajax reloading my page

This is probably the new Heartbeat API. It is running in intervals from 15 to 60 seconds and offers a simple way to communicate with WordPress per AJAX in the background. You can disable it in JavaScript with wp.heartbeat.stop(); and in PHP with remove_action( ‘admin_init’, ‘wp_auth_check_load’ ); (might not be enough on some pages).

Accessing a random image via ajax

There is an error in your src; <img src=”http://example.com//wp-admin/admin-ajax.php?action=random_banner”> Try this one: <img src=”http://example.com/wp-admin/admin-ajax.php?action=random_banner”> or <img src=”https://wordpress.stackexchange.com/questions/215158/<?php echo admin_url(“admin-ajax.php?action=random_banner’ ); ?>”> You can also use a query to get a random image. AJAX add_action( ‘wp_ajax_random_banner’, ‘random_banner’ ); add_action( ‘wp_ajax_nopriv_random_banner’, ‘random_banner’ ); function random_banner() { // search for 1 random image $image_ids = get_posts( array( ‘post_type’ … Read more

Audio Player not loading when the content is loaded through Ajax, MediaElement.js no applied

I had the same problem. You need to reclassify the mediaelement style and script, like it is explained in this post. So just call this funtion, after your ajax call: function enqueue_mediaelement(){ wp_enqueue_style( ‘wp-mediaelement’ ); wp_enqueue_script( ‘wp-mediaelement’ ); } add_action( ‘wp_enqueue_scripts’, ‘my_enqueue_scripts’ ); If you wanna add your own styles for specific pages (in the … Read more

Ajax not firing properly using Firefox, but works in Chrome

This is the barebones for an AJAX call and response. Take a look and make sure this is working on Chrome and Firefox for you — works for me. <?php // Some function for data we’ll pass function dgx_donate_get_countries_requiring_postal_code() { return “cc postal code stuff…”; } // Register everything add_action(‘init’, function () { // Add … Read more

jQuery UI Autocomplete showing all results

You get all terms because you’re asking for all terms, in fact, the line $tradeList = get_terms(‘trade’); just get all the terms, ignoring the ‘term’ query string passed to file. If you want to get all the terms “filterd” you have to use the string in the query, something like: include_once( ‘../../../wp-load.php’ ); // adjust … Read more

Ajax with OOP doesn’t work

You need to create a new instance of the class so that your constructor is called and your actions are registered. e.g. you need to add something like $test = new PR_Test; below the definition of PR_Test.