Skip to:
Content
Pages
Categories
Search
Top
Bottom

Add Friend button with ajax


  • DAM
    Participant

    @damland

    Hello,
    I’ve added the add as friend button inside my homepage and it works (bp_add_friend_button), but its not using ajax like on the members directory. When I click on “Add friend” it reload the page, how can I make it add to friend without reload the page?
    Thanks

Viewing 9 replies - 1 through 9 (of 9 total)

  • Prashant Singh
    Participant

    @prashantvatsh

    It’s because the js code is written to work with buddypress pages. Still you can take references from here https://stackoverflow.com/questions/14491524/adding-add-friend-button-anywhere-in-the-buddypress-site
    And see if this of any help or not.

    Thanks


    DAM
    Participant

    @damland

    no, I know how to add the add-friend button but do I need to include the buddypress js somewhere to make it works with ajax? thanks


    Prashant Singh
    Participant

    @prashantvatsh

    You can try enqueuing that with the conditional tag like:

    function ps_buddypress_js_load(){
     if(is_home()){
      wp_register_script('buddypress', plugins_url( '/buddypress/bp-templates/bp-legacy/js/buddypress.js' , 'buddypress' ) ); 
      wp_enqueue_script('buddypress'); 
     }
    }
    add_action('wp_enqueue_scripts', 'ps_buddypress_js_load');

    If you are using the nouveau template then can change the path accordingly.

    Thanks


    DAM
    Participant

    @damland

    Thanks, I’ve tried the code but its not working with both nouveau and legacy

    @prashantvatsh


    DAM
    Participant

    @damland

    any news about it @prashantvatsh thanks


    Prashant Singh
    Participant

    @prashantvatsh

    Hi,

    Sorry for the delay. I am not on my system but you can debug the code by echoing something just after is_home(){ to see if it is coming in the condition.

    If you don’t know how to code, no worries I will check and reply soon.


    DAM
    Participant

    @damland

    @prashantvatsh the condition is ok, the problem is that even if I include buddypress.js or buddypress-nouveau.js its not working


    Prashant Singh
    Participant

    @prashantvatsh

    Ok, please let me know which template pack you are using right now?


    charlotteoswald
    Participant

    @charlotteoswald

    Hi, sorry to jump on this thread but I’ve written my own and gotten nowhere. I need to bind the “add friend” action onto a jquery event. This means I can’t have the page reload when a new friend request is sent. Is there a way to trigger “add friend” in ajax/jquery without the user clicking on anything or the page reloading? It needs to happen in the background.
    Thanks!

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.
Skip to toolbar