Possible Duplicate:
Problem with page loading content, inside content
so im having problems, the two pieces of code i will reprint worked fine until is introduced a jQuery plugin. Firstly the JavaScript:
$(document).ready(function() {
$.address.crawlable(true).init(function(event) {
$('.nav a').address();
}).change(function(event) {
$('.nav a').each(function() {
$(this).toggleClass('selected', $(this).attr('href') == '#!' + event.value);
});
fragment = event.value.slice(1).replace('!', '');
$('.content').load('http://mysite.com/test/'+fragment+'?ajax=1');
});
});
And now the PHP:
<?php
$base = 'http://mysite.com/test';
include('data.php');
if ($fragment = $_GET['_escaped_fragment_']) {
// OPTION 1: if Google is reqesting an '_escaped_fragment_=' page, then redirect to a clean URL
header("Location: $base/$fragment", 1, 301);
exit;
}
if ($_GET['url']){
// If there's a URL parameter, then load the data.
$data = loaddata($_GET['url']);
if ($_GET['ajax'] == 1){
// OPTION 2: If the user's browser is requesting just the data (as an AJAX request), that's all we'll return
echo $data;
exit;
}
} else {
$data = '<p>Select a link from above to get started :)</p>';
}
//OPTION 3: a user or bot is requesting an HTML page, and we're return that to them now.
?>
Whats happening is visible here: http://laynestaley.co.uk/test/
The page load is fired and then constantly fired over and over, loading the test
index into a div with class content
.
Why do these two samples not work together?
Your root page is loading itself into the div.
In a quick and dirty way, you could just check to make sure
if (document.url != 'http://laynestaley.co.uk/test/#!/') {
$('.content').load('http://mysite.com/test/'+fragment+'?ajax=1');
}