Last active
August 29, 2015 14:18
-
-
Save freundTech/7e8a88e433cc560fca6c to your computer and use it in GitHub Desktop.
ajax
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
$(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