Jump to content

Issue using Ajax with the delayed output


Danjuan
 Share

Recommended Posts

Hey guys

i've just started with processwire so be gentle.

I've managed to use ajax on the site to load dynamic content using the delayed output method but it seems to be duplicating my navigation menu.

In my main.inc file I have the following: Navigation and Content.

<!doctype html>
<html lang="en">
<head>
	<script type="text/javascript">
	$(document).ready(function() {
		$("#topnav a").click(function() {

			$("#topnav a.on").removeClass('on'); // unhighlight selected nav item...
			$(this).addClass('on'); // ...and highlight new nav item
			$(".content").html("<p>Loading...</p>");

			$.get($(this).attr('href'), function(data) {
				$(".content").html(data);
			});

			return false;
		});
	});
</script>
</head>
<body>
<ul id='topnav'><?php

				// Create the top navigation list by listing the children of the homepage.
				// If the section we are in is the current (identified by $page->rootParent)
				// then note it with <a class='on'> so we can style it differently in our CSS.
				// In this case we also want the homepage to be part of our top navigation,
				// so we prepend it to the pages we cycle through:

				$homepage = $pages->get("/");
				$children = $homepage->children;
				$children->prepend($homepage);

				foreach($children as $child) {
					$class = $child === $page->rootParent ? " class='on'" : '';
					echo "<li><a$class href='{$child->url}'>{$child->title}</a></li>";
				}

			?></ul>
<div class='content'>
  <?= $content ?>
​</div>
</body>
</html> 
 

Here's my home.php (Other template files are the same for the time being):

<?php
$content = $page->body;
?> 

It replaces the content just fine but I don't want it duplicating the rest of the page?

What am I doing wrong?

Edited by Danjuan
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...