Search code examples
phpajaxwidgetsocialengine

Calling a widget using ajax on SocialEngine


I want to know if it is possible to make a ajax call on SocialEngine Widget. Like I know we can make an ajax call on the method of any controller but with widgets is it possible too? If it is. Can anyone tell how it can be done.


Solution

  • Yes, it's possible, you can make ajax call to Widget controller.

    Check existing widgets, how they coded the pagination ajax, you need to do the same.

    index.tpl js code

        en4.core.request.send(new Request.HTML({
    
        url : en4.core.baseUrl + 'widget/index/content_id/' + <?php echo sprintf('%d', $this->identity) ?>,
    
        data : {
          format : 'html',
          param1 : 'value1',
          param2 : 'value2',
          param3 : 'value3',
          subject : en4.core.subject.guid
        },
    
         onSuccess : function(){
    
        }
      }), {
        'element' :  $('events_tomorrow').getParent()
      })
    });
    

    In the Controller.php you can check the ajax request and parameters to perform actions.