Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Ajax cancelled by Redirect


Go to End


1614 Views

Avatar
electronic-womble

Community Member, 7 Posts

25 May 2011 at 4:27am

I have a setup with two page types - ImagesPageHolder and ImagesPage - with ImagesPages being the children of an ImagesPageHolder. The Holder page has no content but simply redirects to the first child page. The ImagesPage returns slimmed down content when requested with ajax.

However, this causes an issue when requesting the Holder page with ajax, as the redirect seems to strip the ajax information from the request, with the result that the full ImagePage is returned, not the slimmed down version.

My current workaround in the ImagesPageHolder controller is this:

public function init() {
  parent::init();
  Director::redirect($this->Children()->First()->Link() . (Director::is_ajax() ? '?ajax=1' : ''));
}

However, this feels like a hack to me, especially as I'd like to reserve the 'ajax' param for debugging only.

Any suggestions?

Thanks.