Ajax friends requests

Hello to all, can you please help me .How can i turn this code , to make an ajax request? Thanks

 

if (check_entity_relationship($user->getGUID(), "friendrequest", $entity->getGUID())) {
            // pending request
            $returnvalue[] = ElggMenuItem::factory(array(
                "name" => "friend_request",
                "text" => elgg_echo("friend_request:friend:add:pending"),
                "href" => "friend_request/" . $user->username . "#friend_request_sent_listing",
                "priority" => 500
            ));
  • There's quite a few steps in order to "ajaxify" things:

    1. Register action (or ajax view if there's no sensitive data required)
    2. Custom PHP file with necessary Elgg functions and output link/button
    3. jQuery click() listener function for custom button
    4. Inside the jQuery click function should use elgg.action() function for the ajax request

    That's pretty much it I think. See the message board core plugin for an example.