Уважаемые спецы что скажите по поводу такой реализации AJAX + History API.
Хотелось бы услышать что вы думаете по этому поводу, с какими могу столкнуться неприятностями.
Не судите строго я только начинаю изучать JS и AJAX.
function createRequestObject() {
try {return new XMLHttpRequest()}
catch (e) {
try {return new ActiveXObject('Msxml2.XMLHTTP')}
catch (e) {
try {return new ActiveXObject('Microsoft.XMLHTTP')}
catch (e) {return null;}
}
}
}
function showContent(event, link) {
var nameLink = link.innerHTML;
uploadContent(link.href);
history.pushState({title: nameLink, href: link.href}, null, link.href);
updateTitle(nameLink);
event.preventDefault();
}
function updateTitle(title) {
var elm = document.getElementsByTagName('title')[0];
elm.innerHTML = title;
}
var content = document.getElementById('content');
var http = createRequestObject();
if (http) {
http.open("GET", link);
http.onreadystatechange = function () {
if (http.readyState == 4) {
content.innerHTML = http.responseText;
}
};
http.send(null);
}
else {
document.location = link;
}
}
function ready(e) {
if (e.state != null)
uploadContent(e.state.href);
else uploadContent("http://localhost");
if (e.state != null)
updateTitle(e.state.title);
else updateTitle("Главная");
e.preventDefault();
}
window.setTimeout(function () {
window.addEventListener("popstate", ready, false);
}, 500);