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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Simply load pages with AJAX - Tutorial?

Go to End

4 Posts   1409 Views


Community Member, 65 Posts

25 December 2011 at 4:12am

I was wondering if there is any simple tutorial to load all pages via AJAX if JavaScript is present. The only thing I'd like to do is to not load the whole page (and the viewport to be white) when the user clicks onto a menu link. Has anybody done that yet?



Community Member, 288 Posts

25 December 2011 at 7:56am

It's certainly doable but it's a rather bad idea. If you're switching from one page to another AJAX kind of loses it's purpose. The idea is to be able to switch or update certain elements of a page without having to make the whole round trip to the server but if you're loading a totally new page then that round trip is justified.

What you could do, if you're really really sure that you want to do this is to put an index() method in your controller. In that index method you check if Director::is_ajax() and if it is you just render the Layout template and not the rest. If it's not an AJAX request then you render all of it like you usually do.


Community Member, 65 Posts

25 December 2011 at 8:00am

I think that's exactly what I want to do. In this case, the page type is the same so all of the scripts, css-files and so on can be the same, only the content-box would have to be loaded. I'll try the index-function you mentioned. Thanks.


Community Member, 1 Post

26 December 2011 at 8:27pm

I was same problem faced. now i have read these an solved.....

thanks for sharing....