My current issue involves loading a page via ajax using history.pushState
. The page loads successfully, but the back button does not work as expected. I have included my code below for reference:
function processAjaxData(response, urlPath){
document.write(response)
document.title = '';
window.history.pushState({"html":response,"pageTitle":""}, "", urlPath);
}
$('#apply_loader').click(function(e){
var nextPage = $(this).attr('href');
$.get(nextPage, // url
function (data, textStatus, jqXHR) { // success callback
processAjaxData(data,nextPage);
}
);
});
To address this issue, I am attempting to utilize popstate
to capture the back button click event. Here is the relevant code snippet:
$(window).on('popstate', function(event) {
console.log('asd');
location.reload();
});