0

Im programing website, I use this code before and it works perfect but now when I want to use some flash parts its realoading all website everytime I click link.

Source Code:

 <!DOCTYPE html>
<html>
<head>

<title>Hot King Staff</title>
<meta charset="utf-8">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="tagi"  />
<meta name="Author" content="Filip Jóźwiak" />
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jquB895.js"></script>



</head>
<body>

<div id="cialo">
<?php include('header.php'); ?> 
<?php include('menu.php'); ?>


</div>


<div id="content">

<?php
         $id = isset($_GET['id']) ? $_GET['id'] : '';
         switch($id)
{
              case '':
                     include 'content/news.php';
              break;

              case '2':
                     include 'content/dogs.php';
              break;

              case '3':
                     include 'content/training.php';
              break;

              case '4':
                     include 'content/links.php';
              break;

              case '5':
                     include 'content/contact.php';
              break;

             default:
                     echo 'Taka strona nie istnieje';
              break;
       }
?>




</div>
</body>
</html>

and this is code of my menu.php

  <!doctype html>
<html>
<head>
<meta charset="utf-8">

    </head>
    <body>

    <a href="index.php"><div id="news"></div></a>
    <a href="index.php?id=2"><div id="dogs"></div></a>
    <a href="index.php?id=3"><div id="training"></div></a>
    <a href="index.php?id=4"><div id="links"></div></a>
    <a href="index.php?id=5"><div id="contact"></div></a>
    </body>
    </html>

Can you help me with that, thanks for response.

3
  • Yeah, your question isn't clear. Commented May 31, 2015 at 22:08
  • Sorry, I wrote not clear - when I click on any link its refresh all site over again and I want only to reload only content div because website is a little heavy and its not look nice when it reload all flash animation over again. Commented May 31, 2015 at 22:08
  • That would need to be done using JavaScript. PHP is not capable of hot-swapping content client-side. Commented May 31, 2015 at 22:10

1 Answer 1

1

first: you are including ur menu, why did you set:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">

</head>
<body>

<a href="index.php"><div id="news"></div></a>
<a href="index.php?id=2"><div id="dogs"></div></a>
<a href="index.php?id=3"><div id="training"></div></a>
<a href="index.php?id=4"><div id="links"></div></a>
<a href="index.php?id=5"><div id="contact"></div></a>
</body>
</html>

??? if you wnt to include this, than include just your menu:

<a href="index.php"><div id="news"></div></a>
<a href="index.php?id=2"><div id="dogs"></div></a>
<a href="index.php?id=3"><div id="training"></div></a>
<a href="index.php?id=4"><div id="links"></div></a>
<a href="index.php?id=5"><div id="contact"></div></a>

If you want to change a specific part of the site without refreshing it completly you could use jQuery

In your main page add this piece of jquery but notice that before you can use jquery you will need to include it in your website

$.ajax({
    url: '/pages.php?page=dogs
    success: function(data) {
        $('#content').innerHTML(data);
    }
});

Now create a pages.php

<?php
    if($_SERVER['REQUEST_METHOD'] == 'GET') {
        if (isset($_GET['page'])) {
            $page = $_GET['page'];

            switch($page)
            {
                case 'dogs':
                    echo 'dogs';
                    break;
                case 'cats':
                    echo 'cats';
                    break;
                default:
                    echo 'Taka strona nie istnieje';
                    break;
            }
        }
    }
?>

And don't forget to add the content div in your main page like so

<div id="content"></div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.