Add elgg.action to href

Hello to all i,ve got this href "href" => "action/friends/add?friend=" . $entity->getGUID(), how do i turn it to something like this "href" => "javascript:elgg.action('friends/add?friend=', { $entity->getGUID() })", to make a Ajax call?

Can someone help me please??

 

Thanks

  • Simplest way is to use jquery bindings:

    $(document).on('click', '.link-class', function(e) {

        e.preventDefault();

        elgg.action($(this).attr('href'), {

            success: function(result) {

                // do something when the action is complete

            }

        });

    });