Доброго времени суток. Я понимаю, что вопросы и ответы на тему History API уже тут были, но они мне не помогли, поэтому прошу помощи ещё раз. Всё в роде бы работает, кроме кнопки "назад". Когда нажимаю в браузере на кнопку "назад", то url меняется на нужный, но данные не обновляются.
Вот код:
window.onload = function() {
var anchors = document.getElementsByTagName('a');
for( var i = 0; i < anchors.length; i++ ) {
anchors[i].onclick = loader;
}
function loader() {
var state = {
title: this.getAttribute("title"),
url: this.getAttribute("href", 2)
};
history.pushState(state, state.title, state.url);
$.ajax({
type: 'POST',
url: state.url,
data: { data: 'text' },
success: function(html) {
$('#content').html(html);
}
});
return false;
}
}
window.onpopstate = function(event) {
console.log('onpopstate event was fired');
$.ajax({
type: 'POST',
url: event.url,
data: { data: 'text' },
success: function(html) {
history.replaceState(event, event.title, event.url);
$('#content').html(html);
}
});
};
Прошу помощи в данном вопросе.