Get elements via ajax

Well, I am a new coder in elgg, and I wanted to know if there is in elgg some function (or plugin) that can make me ajax anything in the site.

I am trying to reduce the page load by ajaxing somethings in the profile of my mebers, this way these things will only load if the user click to see it.

If there's no elgg plugin or function that can handle that, can someone help me with this?

  • http://docs.elgg.org/wiki/Javascript/Ajax

     

    You want to use the elgg.get() javascript method for calling ajax views

    Any views you need to get using ajax should go through the ajax pagehandler and be registered using elgg_register_ajax_view

     

    eg. you have a view called 'myplugin/view'

    In your init you'll need

    elgg_register_ajax_view('myplugin/view');

     

    And that view can be reached at [url]/ajax/myplugin/view

  • Well, then I have a problem...

    I have a div in a default profile that have 3 photos of the profile owner.But I want to make these 3 photos load only if the user click in "see photos", without load the page.

    Right now, without ajax, I'm using this code:

    <div>

    $content = elgg_list_entities(array(
    'type' => 'object',
    'subtype' => 'image',
    'limit' => 3,
    'owner_guid' => $owner->guid,
    'full_view' => false,
    'list_type' => 'gallery',
    'list_type_toggle' => true,
    'pagination' => false,
    ));

     

    echo $content;

    </div>

    How could I apply ajax to this or to the div, so I can load the images only if i click?

  • as a slight tangent.. what is the benefit of using an elgg ajax view at this point?

  • You take exactly the markup you have there, and move it into the ajax view

    You create the 'see photos' link

     

    Register a jquery function to fire when the link is clicked, in the function you'll use the elgg.get() method to get your images, then use jquery to insert them into the markup

     

    elgg.get('ajax/view/myplugin/imageview', {
          timeout: 30000,
          data: {
            guid: guid,
            pageowner: elgg.get_page_owner_guid()
          },
          success: function(result, success, xhr){
                $('.some-class').html(result);
          },
        });
  • thanks matt - so does registering the ajax view aid in the passing of variable from php/html to javascript in some way?
    i am coding ajax views and not using the ajax register method presently.

  • If you don't register the view, the URL /ajax/view/... won't work. You still have to use get_input() in the view when passing in data via GET/POST.

    Basically the view becomes a single application for that request. This is arguably not a good separation of logic from the view, but that's a topic for another day.

  • ok, yes.. i thought that must be the case since i am using get_input... i will explore this further by looking at some of the few 'ajaxed' plugins i know of.

  • i appreciate the value of passing data via variables in ajax - yet that prevents a direct url being saved of the content of a view, which is made possible by using variables in the url..
    hmm...

  • Original URL should be in http referer.

  • i was thinking more of the ability of site visitors to store the url and reload that page with precise variables.. or are you presenting the idea of setting the address bar via js from the URL stored by http referer variable?

Performance and Scalability

Performance and Scalability

If you've got a need for speed, this group is for you.