Reputation:
I am building a web application Java Spring MVC, JSPs, and jQuery.
I have a URL like this:
http://myserver/myapp/showuser/55
Which shows the "view user" page (for user id '55').
I also have an "edit user" page and after successful edit, I redirect to the "view user" page by going here:
http://myserver/myapp/showuser/55?successMsg=Successfully edited User.
The "success message" is parsed from the URL parameters and displayed on the screen.
It works well, but ...
QUESTION: How can I pass the "successMsg" value to the GET without making it part of the URL itself?
Upvotes: 0
Views: 483
Reputation: 301
For Plain JavaScript Web solution:
You can use History pushState
method to do that.
History's state
is similar to params but it is hidden from the URL.
To do that, simply:
const state = { successMsg: 'Successfully edited User'};
const title = '';
const url = 'myserver/myapp/showuser/';
history.pushState(state, title, url);
In your Show User page, access the state like
console.log(history.state) // { successMsg: 'Successfully edited User'}
Upvotes: 0
Reputation: 432
You can use btoa() and atob() to convert to and from base64 encoding.
Upvotes: 2