Reputation: 1457
I am posting data to a php file, which returns a message. Then I'd like to redirect to a new page and display the message at the top of the new page.
I was thinking of something like this, except that I want to prepend AFTER redirecting.
$.post('process.php', {"data": data}, function( message ){
window.location.pathname = '/';
$( '#content' ).prepend( message );
});
Upvotes: 0
Views: 72
Reputation: 10142
You can use JavaScript localStorage API to save message and display to the page.
$.post('process.php', {"data": data}, function( message ){
localStorage.setItem('message', message); //Store the message
window.location.pathname = '/';
});
Then on next page where redirection made:
<script>
$(document).ready(function() {
$('#content').prepend(localStorage.getItem('message')); //Display the content if null, nothing will be insert to DOM
});
</script>
Upvotes: 1