WordPress.org

Ready to get started?Download WordPress

Forums

Passing arguments to a ajax callback? (3 posts)

  1. goffi
    Member
    Posted 3 years ago #

    Hi,

    I'm trying to pass a value to an ajax call back. I have already tried:

    do_action('wp_ajax_update', 123 );
    add_action( 'wp_ajax_update', 'my_call_back', 10, 1 );

    and also

    do_action('update', 123 );
    add_action( 'wp_ajax_update', 'my_call_back', 10, 1 );

    but doesn't work.

    Which is the correct way?

    Tnx!

  2. Mark / t31os
    Moderator
    Posted 3 years ago #

    Which is the correct way?

    Neither really, the do_action already happens inside WP, all you need do is have a callback function in place for whatever action your ajax function sends to WordPress's ajax file.

    Most simple example of using an ajax callback is the one found here.
    http://codex.wordpress.org/AJAX_in_Plugins

    Beyond that check out:
    http://codex.wordpress.org/AJAX_in_Plugins#Further_Reading_-_External_Resources

    Also more here:
    http://codex.wordpress.org/AJAX

  3. Ian Dunn
    Member
    Posted 2 years ago #

    I also want to do this, but I don't think it's possible. /wp-admin/admin-ajax.php just calls

    do_action( 'wp_ajax_nopriv_' . $_REQUEST['action'] );

    and

    do_action( 'wp_ajax_' . $_GET['action'] );

    So, it's not passing in additional parameters to the callback function. You'll have to include any variables you want in the POST request and then parse them out inside the callback function.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags