Jump to content

Add variable to url without reloading page


idm1

Recommended Posts

Hi

 

How can I carry out this code without reloading the page:

<ul>
  <li><a href="?page=1">link 1</a></li>
  <li><a href="?page=2">link 2</a></li>
  <li><a href="?page=3">link 3</a></li>
  <li><a href="?page=4">link 4</a></li>
</ul>

  <?php
        $page=$_GET['page'];
        if ($page == '1'){
             include 'includes/page1.php';
        }
        if ($page == '2'){
            include 'includes/page2.php';
        }
        if ($page == '3'){
            include 'includes/page3.php';
        }
        if ($page == '4'){
            include 'includes/page4.php';
        }
   ?>

Or can someone advise a better way to include and page when a link is clicked?

 

Many thanks

 

Link to comment
Share on other sites

If I'm following your logic.  when the web user clicks link 1, you want to load "include/page1.php".  PHP is a server side technology. In order to run the that pages code, your either have to reload or user a asynchronous programming model like AJAX.  AJAX can execute code in the background.

 

Look into JQuery $.ajax as possible solution.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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