Skip to content

Instantly share code, notes, and snippets.

@stvedt
Created April 8, 2013 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stvedt/5337586 to your computer and use it in GitHub Desktop.
Save stvedt/5337586 to your computer and use it in GitHub Desktop.
Demonstration of a gracefully degrading and search engine optimized AJAX technique.
<!DOCTYPE html>
<html>
<head>
<title>Example by Stephen Tvedt</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>
<nav>
<a href="index.html">Home</a>
<a href="about.html">About</a>
</nav>
<div id="content">
<h1>About</h1>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Example by Stephen Tvedt</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>
<nav>
<a href="index.html">Home</a>
<a href="about.html">About</a>
</nav>
<div id="content">
<h1>Home</h1>
</div>
<script>
var $content = $('#content');
$('nav a').click(function(e){
e.preventDefault();
var $page = $(this).attr('href');
$content.load($page + ' #content');
window.location.hash = $page;
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment