In my NodeJS app, I am trying to keep the (data) value that application sends with res.send() after ajax request is .done() successfully with the form data submission.
ajax Request
$.ajax({
url: "/users",
type: "POST",
contentType: "application/json",
data: JSON.stringify(payload)
})
.done(function (data, status, jqXHR) {
window.location.reload();
$("#output").html(data) // User saved in Database with ID: xxx
});
.fail(function(data) {
console.log( "error" );
});
.always(function() {
console.log("processed")
});
The (data) value (which is sent by the back-end) is being projected as a message in the #output on .done() but the window.location.reload() reloads the page (as it should) and wipes out from existence the message I need to show after the page reloads.
How can it happen to transfer the (data) value so I can project it after the page reloads ?
Obviously I do not want to put it on an alert() or create a delay timer for the reload.