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.

General Questions /

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

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

Simply load pages with AJAX - Tutorial?


Reply


4 Posts   1005 Views

Avatar
oleze

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?

Greatz
Oliver

Avatar
MarcusDalgren

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.

Avatar
oleze

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.

Avatar
TechticSolutions

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....