I have a problem in my code. The aim is to complete a simple form, when the user clicks on a submit button. It does an Ajax request. After the Ajax request succeeded, I use windows.history.back()
to go to the previous page and here I want to refresh this page, to refresh values which were modified by the form. Have you any idea about that?
$("#form_edit").submit(function (e) {
e.preventDefault();
$.ajax({
url: $("#form_edit").attr("action"),
type: "POST",
cache: false,
data: $(this).serialize(),
success: function (data) {
if (data === true) {
alert("Modification réussie !");
window.history.back();
location.reload(); // <= on success i want to refresh previous page
} else {
alert("Modification échouée !");
}
},
error: function () {
alert("Modification échouée !");
},
});
});
It will have already gone back before it executes the reload.
You would be better off to replace:
window.history.back();
location.reload();
with:
window.location.replace("pagehere.html");