Skip to:
Content
Pages
Categories
Search
Top
Bottom

using ajax in a component


  • grosbouff
    Participant

    @grosbouff

    Hi, I don’t understand well enough how to use AJAX in a BP component.

    I’ve tryed to look at the existing plugins (bp-messages, bp-groups) but I don’t find any references of to the functions set in the bp-..-ajax.php files elsewhere that the definition of the function itself.

    e.g. look at directory-groups.js : we have such things.

    jQuery.post( ajaxurl, {
    action: 'directory_groups',
    'cookie': encodeURIComponent(document.cookie),
    '_wpnonce': jQuery("input#_wpnonce-group-filter").val(),
    'letter': letter[1],
    'page': 1
    },

    What does ‘directory_groups’ refers to ?

    There is no directory_groups function…

    Or maybe does it refers to that function of the ajax file ?

    function bp_core_ajax_directory_groups() {
    global $bp;

    check_ajax_referer('directory_groups');

    load_template( TEMPLATEPATH . '/directories/groups/groups-loop.php' );
    }
    add_action( 'wp_ajax_directory_groups', 'bp_core_ajax_directory_groups' );

    I don’t understand how this works. Really… If someone could help me ?

    And what is “check_ajax_referer” ?

Viewing 1 replies (of 1 total)
  • You’ve got it correct. The action from the js is taken and called with an action prefixed with “wp_ajax_”, just like above.

    Check_ajax_referer() checks that a valid nonce was passed with the request – to find out more about nonces, see here.

Viewing 1 replies (of 1 total)
  • The topic ‘using ajax in a component’ is closed to new replies.
Skip to toolbar