In my project I am using this Ajax function (below) to get the content (it works really well ^^).
Anyway I would like to have a nicer looking URL (to be honest I am no fan of the hashtag,) with the script I have been using until now I get something like this: http://example.com/#sitename
To change that I did some research: I learnd this: the window.history.pushState('page2', 'Title', '/page2.php');
JavaScript line (see here or here more information on updating URL without reloading)
I should be able to actually change the url so that I would like it. now my problem is that I am a total beginner whit programming (And when I tried to include it in to the code it broke and nothing worked anymore.) and wanted to ask if someone could help me include it in the code (below)
Also I heard of the History.js - library if I read correctly this should also should do the trick whit, but like I said I am inexperienced and have to ask how to include it to the ajax-call (I mean to include it in to my code) or is that not possible?
$(document).ready(function() {
var e = "", t = $("#content");
$("ul:not(.no) li a").click(function() {
window.location.hash = $(this).attr("href");
return false;
});
$(window).bind("hashchange", function() {
e = window.location.hash.substring(1);
url = e;
if (e) {
t.fadeOut(200, function() {
url = url.replace("#", "");
$("#loading").css("visibility", "visible");
$.ajax({
type : "POST",
url : "load_page.php",
data : "page=" + url,
success : function(e) {
if (parseInt(e) != 0) {
t.fadeIn(200, function() {
$("#content").html(e);
var $title = $("#title").text();
document.title = "JuBla | " + $title;
});
}
$("#loading").css("visibility", "hidden");
}
});
$("li a").removeClass("current");
$('li a[href="" + e + ""]').addClass("current");
//my attempted solution // window.history.pushState('/'+ url, $title, '/' + url + '/')
});
}
});
$(window).trigger("hashchange");
});