WordPress Ajax Data problem

$.post(ajaxurl,{ action:’master_ajaxurl’, option: $(this).find(“option:selected”).val(), // use option also here }, function(data){ //adds the echoed response to our container // alert(data); $(“#details”).html(data); } ); Move action and functions into function.php file make some changes as commented add_action(‘wp_ajax_master_ajaxurl’, ‘master_ajaxurl’); add_action(‘wp_ajax_nopriv_master_ajaxurl’, ‘master_ajaxurl’); function master_ajaxurl() { $myOpt = $_POST[‘option’]; // use option instead of data echo bringDetails($myOpt); die(); } … Read more

WordPress AJAX in header.php

There are tons of questions about using Ajax, so your question could be easily marked as duplicated but I see so BIG mistakes that I can’t say to you that the question is duplicated without explaining your mistakes. The Ajax in WordPress is handled in admin-ajax.php file, wehre you correctly sent the ajax request (see … Read more

Basic ajax call in WordPress

You have to use the admin-ajax handler to do the AJAX call. Replace file.php in var url = “file.php”; with yoursite.com/wp-admin/admin-ajax.php?action=simple_ajax And in your plugin / functions.php file, add add_action(‘wp_ajax_nopriv_simple_ajax’,’process_simple_ajax’); //for non logged in user add_action(‘wp_ajax_simple_ajax’,’process_simple_ajax’); //for nlogged in user function process_simple_ajax(){ $data = $_REQUEST; // retrieve your submitted data wp_send_json($data); // return the processed … Read more

Prevent wp_debug from polluting ajax within plugin

“How can I prevent unexpected output from reaching the browser/interfering with my AJAX response?” The Problem Something in your installation is generating “unexpected output,” that is, it’s creating content or data which should not be there if WordPress is running smoothly. This could imply a misconfigured server environment, a faulty WordPress installation, a bad database … Read more

Custom WordPress+PHP+MYSQL+AJAX form, submit event not captured by Javascript, but does POST data to the DB

If you’re releasing this as a plugin, you absolutely must use the AJAX API. It’s super easy: /** * Handle the request and return the result. */ function alumni_process_request() { global $wpdb; // All your processing code from your original question, except for loading WordPress! return $data; } /** * AJAX handler for the “alumni” … Read more

How to remove an Ajax action

The main issue I was having is that when an ajax request hits not all hooks are being loaded. I used this code: $return = array(); foreach( $GLOBALS[‘wp_actions’] as $action => $count ) { $return[“message”] .= $action . “, “; } wp_send_json($return); This showed me the hooks that were running before and I got it … Read more