WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to make an AJAX call for a plugin.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
$.post(
    '<?php admin_url('admin-ajax.php'); ?>',
    {
        action : 'AAA'
    },
    function( response ) {
        alert( "[[[[" + response + "]]]]" );
    }
);
}

The ajax call is working fine.

add_action( 'wp_ajax_nopriv_AAA', 'fAAA' );
add_action( 'wp_ajax_AAA', 'fAAA' );

function fAAA(){
      echo "123";
      die();
}

For some reason my fAAA is not getting called.

I used var_dump( $wp_filter['wp_ajax_nopriv_AAA'] ); to check the actions. * in the plugin, it showed that the action is added * when i looked in admin-ajax.php, the action is not there.

Any help?

share|improve this question

Aside from @Tareq answer (which is your main problem), you should

  • wp_register_script and the wp_enqueue_script
  • load your local copy of jQuery instead of the one from Google CDN
  • localize your script using wp_localize_script
share|improve this answer

You didn't echo admin_url('admin-ajax.php')

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.