Skip to content

Instantly share code, notes, and snippets.

@freundTech
Last active August 29, 2015 14:18
Show Gist options
  • Save freundTech/7e8a88e433cc560fca6c to your computer and use it in GitHub Desktop.
Save freundTech/7e8a88e433cc560fca6c to your computer and use it in GitHub Desktop.
ajax
$(document).ready(function() {
$("a").click(clicklink);
});
$(window).on("popstate", function(popstate) {
var link = popstate.originalEvent.state || "/";
openlink(link);
});
var clicklink = function() {
var link = $(this).attr("href");
if(link.charAt(0) == '/' || link.charAt(0) == '.') {
if(window.history.state !== link) {
window.history.pushState(link, "", link);
}
openlink(link);
return false;
}
};
var openlink = function(link) {
var url = link.split("/");
if(url[1] === "") {
url[1] = "index";
}
$.ajax("/content/"+url[1]+".php?site="+url[2], {
success: function(data) {
$("#content").html(data);
$("a").off("click");
$("a").click(clicklink);
},
error: function() {
$("#content").html("<h3>Please check your internet connection.</h3>");
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment