In the response to an AJAX call:
$.ajax({
type: "POST",
dataType: 'json',
data: {
'descripcion': descripcion
},
url: "<?php echo site_url();?>"+"admin",
success : function(data) {
console.log(data);
if (data == "1") {
swal(
'Correcto!',
'Grupo agregado correctamente!',
'success'
).then(function () {
$('#add').modal('close');
document.location.href = "test#tab1";
})
}else if (data == "2") {
swal(
'Error!',
'Ha ocurrido un error, contacte al administrador!',
'error'
)
}else if (data == "0") {
swal(
'Error!',
'Todos los campos son obligatorios!',
'error'
)
}
}
});
I want to reload the page (same URL), but with a #
different (hash or fragment). The problem I have is in the line:
document.location.href = "test#tab1";
Since it doesn't work, that is, it doesn't reload the page in the #tab1
.
If I remove it , it #tab1
works normally, but it stays at the top of the page and does not go to that element.
How could I fix this?
The browser realizes it's the same page, so it doesn't try to reload it, it just looks for the
#tab1
within the current page.For it to cool down, you have to change the
#tab1
and force it withlocation.reload(true)