Jump to content

[SOLVED] Loading a page within a page without reloading the entire page


Duepilind

Recommended Posts

Hello,

 

I've been using a rather simple tab menu/website structure. Each tab link referred to an include located within a switch statement. Thus, all page changes took place within the index file. Here is a condensed version of my Index file.

 

<?php $highr = ($_GET['page']); ?>
            <ul id="nav">
            
<?php
	// This is the script for the menu
    // Menu items
    $mainMenu['Home']      = 'index.php?page=home';
    $mainMenu['Music'] 	   = 'index.php?page=music';
    $mainMenu['About']     = 'index.php?page=about';

//This part creates the above menu items as tabs
    foreach ($mainMenu as $menu => $link) {
        echo '<li><a href="'.$link.'"';

	//Identifies the active page, if active the tab is given the class="active"
	$wadr = $link;
	$parts = explode("=",$wadr);
	$wadr = $parts['1'];
	if ($highr == $wadr){
		echo ' class="active"';
	}
	echo '>'.$menu.'</a></li>';
    }
?>
            </ul>


<table><tr><td>
<?php
//This is where the pages appear

switch ($_GET['page'])
{
     case "home":
       include('home.php');
       break;
 case "music":
       include('music.php');
       break;
     case "about":
       include('about.php');
       break;
     default:
       include('start.php');
       break;
}
?>
</td><td>
<?php
// This content will not change
include('sidebar.php');
?>
</td></tr></table>

 

 

What I like about this, and want to keep, is the possibility to link directly to a tab through the address bar, for example, writing http://www.domain.com/index.php?page=home would get me to the home tab of my website.

 

However, the current limit is that every time I click a tab, the entire website reloads. Instead, and what I need assistance with, is a method so only the switch method changes rather than the entire website reloads. Any suggestions?

 

I'm assuming the end-result will approach something like the tab system on the following page:

http://www.theoldecookerybook.com/~theopden/wiki/index.php/Colonel_Plomer%27s_Shrewsbury_Cake#tab=Original_text

 

But I'm unsure how to go about this.

 

Thank you beforehand for any assistance!

PHP is parsed before it is sent to the page, so unless you use AJAX, you can't parse it without refreshing the page.

It'd probably be quite easy with AJAX tbh, something like each nav link sends a variable to the server via httpRequest, eg. page=music, and your index file can return the respective page.

Hope this helps...

The last poster touched on it, but basically you want to use AJAX. It's a method combining javascript and a server side language (usually). Basically, javascript makes calls to the server in the background to get the data you need.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.