Created
May 11, 2012 05:23
-
-
Save pgooch/2657696 to your computer and use it in GitHub Desktop.
Proper URLs that SEO and load with javascript and AJAX updated data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This should take everything in the path and pass it to the index file as the path get varible | |
RewriteEngine On | |
RewriteCond %{REQUEST_URI} !index.php | |
RewriteRule (.*) index.php?page=$1 [QSA,L] | |
# More explanation : http://fatfolderdesign.com/583/php/ajax-sites-with-real-url-using-history-pushstate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This will load the file at the path in the appropriate section, inside a div for the ajax to do it's thing */ | |
if($_GET['path']==''){ | |
$_GET['path']=='home'; | |
echo '<div id="ajaxable_content">'; | |
} | |
if($_POST['ajax_load']!='true'){ | |
require_once('inc/header.php'); | |
} | |
require_once($_GET['path'].'.php'); | |
if($_POST['ajax_load']!='true'){ | |
echo '</div>'; | |
require_once('inc/footer.php'); | |
} | |
/* More explanation : http://fatfolderdesign.com/583/php/ajax-sites-with-real-url-using-history-pushstate */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This will take a url and add update the users browser to display it without redirecting, and load the next function | |
function ajax_goto(url){ | |
history.pushState("","New Page Title",url); | |
ajax_load(url); | |
} | |
// This will load the requested content by access the index with the post variable ajax_load | |
function ajax_load(url){ | |
$.ajax({ | |
url: url, | |
method: 'POST', | |
data: 'ajax_load=true', | |
success: function(o){ | |
$('#ajaxable_content').html(o); | |
} | |
}) | |
} | |
// More explanation : http://fatfolderdesign.com/583/php/ajax-sites-with-real-url-using-history-pushstate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment