How to load part of a page

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
hcccs
Forum Newbie
Posts: 1
Joined: Wed Apr 15, 2009 1:43 pm

How to load part of a page

Post by hcccs »

I'm creating a test site using PHP in which I load the navbar,banner and news bar using the 'include' command. All three pages I have so far have these includes in them so everything is loaded every time which seems stupid. When I click on a link in the navbar I want to load the new page only (page1.php page2.php etc). How do I accomplish this?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: How to load part of a page

Post by pickle »

You can use AJAX to retrieve only part of a page from the server, then place it somewhere in the page. You can also use an iframe. Both of these possibilities don't update the URL, so I wouldn't recommend using either one of them.

It may seem redundant to keep loading all the parts of the page each page load - but it's necessary. You don't know that any given request isn't the first request, so you need to make each page have all the parts necessary. Building the page each time is a pretty standard practice.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply