I'm working on a page that loads part of the content by javascript. I am succeeding and even generates and adds a new url to the browser history.
function FiltraItens(criterio){
var UrlJson = baseUrl + "//Json/Listas/ListarItens/";
$.ajax({
method: "GET",
url: UrlJson,
traditional: true,
data:
{
Criterio: criterio
},
beforeSend: function() {
$("div.itens").empty();
},
success: function(view) {
$("div.itens").append(view);
var NovaUrl = "";
if (OldUrlBuscaOuEstado !== "busca")
{
NovaUrl = "?criterio=" + criterio;
window.history.pushState('Object', criterio, NovaUrl);
}
},
error: function(data) {
alert("Falha! Não foi possível retornar os itens, por favor, tente novamente mais tarde.");
}
});
return false;}
Htmt looks like this:
<a href="#ResultadoBusca" onclick="FiltraItens(2)" >carrega itens2</a>
My problem is that by clicking on the back button of the browser the url displayed until it changes, however the content of the page is not retrieved, remaining the same.
It seems like I have to add the popstate listener. But I have no idea how. I already researched many sites and I can not understand ...