I want to create an ajax page and I was wondering how to do it correctly? Essentialy I just need to get page data, and block content.
For now I have quick and dirty solution for the problem, by printing json in ipBeforeResponceSent Event and exiting, but it's ugly..
class Event{
public static function ipBeforeResponseSent($event){
$ajax = ipRequest()->getQuery('ajax');
if ($ajax){
$page = ipContent()->getCurrentPage();
$data['status'] = 'success';
$data['url'] = $page->getLink();
$data['page'] = ipContent()->getBlockContent('main');
$data['title'] = $page->getTitle();
$data['id'] = $page->getId();
$data['pageorder'] = $page->getOrder();
$data['parent'] = $page->getParentId();
$data['timestamp'] = time();
exit(json_encode($data, true));
}
}
}
Javascript side:
$.getJSON(PAGE_URL, {ajax: 'true'}, function(responce) {
if (responce.status == 'success'){
/***/
}
});
Maybe the cleanest solution would be to just send link to my plugin's controller?